Makale numarası: 143258 - Son Gözden Geçirme: 01 Temmuz 2004 Perşembe - Gözden geçirme: 1.3

Tip kitaplığı'nda, sabitleri ve DLL bildirimleri oluşturma

Sistem İpucuBu makale, kullandığınızdan farklı bir işletim sistemine yöneliktir. Sizinle ilgili olmayabilecek makale içeriği devre dışı bırakıldı.

Bu Sayfada

Hepsini aç | Hepsini kapa

Özet

Sabit tanımlar ve bir tür kitaplığı, DLL bildirimlerinde paketlemek çok yararlı olabilir. Visual Basic tür kitaplıkları ve bunların içerikleri erişmenize olanak verir. Bir tür kitaplığına başvuru yaptıktan sonra Visual Basic kullanıcının kendi Nesne Tarayıcısı içindeki bilgileri görüntüleyebilirsiniz. Yardım dizesi de sağlayabilir, tür kitaplıkları de üst bulunan bir tanımı kullanıcının her zaman için bildirimleri ile birlikte kullanılır.

Daha fazla bilgi

Bir tür kitaplığı oluşturmak için <a0></a0>, komut satırına gereken programları UUID.EXE ve MKTYPLIB.EXE. Bu programlar, Visual C++ ile sağlanır.

Biz üç tamsayı sabit, dize sabiti ile bir Windows API bildirimi bir tür kitaplığı oluşturmak istediğinizi varsayın. Aşağıdaki tür kitaplığı üretmek için gereken nesne Açıklama Dili (ODL) kodudur. ODL okuyun ve orada ne her bölümü olduğunu açıklayan açıklamalar olması neden olacaktır biz gerekir.
   [
   // The Universal Unique identifier (UUID), needs to be generated by
   // using uuid.exe program. Then, you paste the value into the type
   // library.
   uuid(006da100-110f-11cf-83b2-00aa0068851c),

   // The Help String comes up in the object browser as the second
   // piece of the library description in the "Libraries/Projects" combo
   // box.
   helpstring("Constants TypeLib"),

   // The Locale Identifier (LCID), identifies the language the type
   // library applies to.
   lcid(0x9),

   // This is the version number of the type library.
   version(1.0)
   ]

   // This is the name of the type library. It comes up in the object
   // browser as the first piece of the library description in the
   // "Libraries/Projects" combo box.
   library MyLib
   {
     // Define numeric constants.
     typedef enum tagConst
        {
          mylibConst1,       // Make the constant mylibconst1 equal to 0.
          mylibConst2=5,     // Make the constant mylibconst2 equal to 5.
          mylibConst3=7      // Make the constant mylibconst3 equal to 7.
        }Constants;

      // You need to define string constants in a module.
      // Modules also need to reference a dll name. In this case you don't
      // need to, so just give it a bogus name.
      [dllname("bogus")]
      module MoreConstants
       {
         // Define a constant mystr and assign it the value StringConstant.
         const LPSTR mystr="StringConstant";
       };

      // Now call a function located in the Windows API, specifically
      // User32.dll. Now you see why you need a dll name here, this is
      // where the API function will come from.
      [dllname("user32.dll")]
      module APIDeclare
       {
         // Give the API function a descriptive help line, this will
         // be seen in the Object browser. Then, you can declare the
         // function. The entry attribute specifies the identifier for the
         // entry point into the dll.
         // The in attribute specifies a parameter as a value going into
         // the function.
         //Note that the following two lines need to be all on one line.
   [helpstring("Test API function Declaration"), entry("CloseWindow")]_
    boolean

   CloseWindow([in] long Winhndl);
       };
   }
				

Bu kod derleme için <a0></a0>, bir metin dosyasına kopyalayın, bunu test.odl çağırın ve komut satırı programı MkTypLib aşağıdaki gibi çalıştırın:
   mktyplib /nocpp test.odl
				

Aşağıdaki ileti görüntülenir:
   Successfully generated type library 'test.tlb'.
				

Visual Basic'ten Tür Kitaplığı'nı kullanma

  1. Visual Basic ile yeni bir proje başlatın.
  2. Araçlar menüsünden başvurular'ı seçin. Bu başvuru getirecektir iletişim kutusu; Gözat düğmesini Test.tlb dosyayı aramak için tıklatın. Dosyayı bulduktan sonra Tamam'ı tıklatın.
  3. Tür kitaplığı şimdi başvuruları listesinde olması, işaretli olduğundan emin olun ve başvurular</a0> iletişim kutusundan çıkmak.
  4. Bir komut düğmesi üzerinde form1 çizin.
  5. Aşağıdaki kodu girin:
          Private Sub Command1_Click()
    
          Dim x As Boolean
    
          'Call the Windows API function CloseWindow without making one
          'declare at all. Note that the CloseWindow API will close the current
          'window.
          x = CloseWindow(Me.hWnd)
    
          'Now print out the value of the constants in the type library
          'using message boxes.
          MsgBox mylibConst1
          MsgBox mylibConst2
          MsgBox mylibConst3
          MsgBox mystr
    
          End Sub
    						
  6. Program çalıştırın; form1 simge durumuna küçültün ve sonra size verilen tür kitaplığında tanımlanan her bir sabit değer için bir ileti kutusu ve her sabit değeri görürsünüz görürsünüz.

Referanslar

<a1>OLE</a1> 2 programcıları başvuru birim 2

Bu makaledeki bilginin uygulandığı durum:
  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 6.0 Professional Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0
  • Microsoft Visual Basic 4.0 Standard Edition
  • Microsoft Visual Basic 4.0 Professional Edition
  • Microsoft Visual Basic 4.0 Professional Edition
  • Microsoft Visual Basic 4.0 16-bit Enterprise Edition
  • Microsoft Visual Basic 4.0 32-Bit Enterprise Edition
Anahtar Kelimeler: 
kbmt kbhowto KB143258 KbMttr
Otomatik TercümeOtomatik Tercüme
ÖNEMLİ: Bu makale, bir kişi tarafından çevrilmek yerine, Microsoft makine-çevirisi yazılımı ile çevrilmiştir. Microsoft size hem kişiler tarafından çevrilmiş, hem de makine-çevrisi ile çevrilmiş makaleler sunar. Böylelikle, bilgi bankamızdaki tüm makalelere, kendi dilinizde ulaşmış olursunuz. Bununla birlikte, makine tarafından çevrilmiş makaleler mükemmel değildir. Bir yabancının sizin dilinizde konuşurken yapabileceği hatalar gibi, makale; kelime dağarcığı, söz dizim kuralları veya dil bilgisi açısından yanlışlar içerebilir. Microsoft, içeriğin yanlış çevrimi veya onun müşteri tarafından kullanımından doğan; kusur, hata veya zarardan sorumlu değildir. Microsoft ayrıca makine çevirisi yazılımını sıkça güncellemektedir.
Makalenin İngilizcesi aşağıdaki gibidir:143258  (http://support.microsoft.com/kb/143258/en-us/ )