???? ID: 189133 - ????? ???????: 03 ?????? 2010 - ??????: 4.0
C DLL ?? ?? ?????? ????????? ?? ??? VB ???? ?? ??? ????? ????? ???? ????
?????? ?????? This article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.
???? ???? ?????? ?? ??? Visual Basic ??? ?????? DLL ??????? ???? C., ???? ?????? ??? ???? ?? ?? ??? ???? ?? ??? ?? ??? ?? ?????? ?? ??? ??? Declare ??? ????? Declare ????? ?? ?? ???????? ??? ?? ?? Visual Basic ??? ?? ???? ??? ???? ?? ??? ??? ????? DLL ?? ???? ??? ????? ??? ?? ??? ?? ???????? ??? ???? ?????? ?? ????????? ?? C ????????? ?????? ?? ??? ???? ?? ???? Visual Basic friendly ????? ????? ???
?? ???? ????????? ???? ?? ?? ????? ?? ??? ??? ?????? ????????? ?? ?? ???? DLL ?? ?? ????????? ?? ????? ??? ?? ?????? ?? ???? ????? Basic ???? ?????
?????? ????????? ??????? ????????? ????? (.tlb ???????) ??? ??????? ?? ????? ???? ???? ???
?? ??? ??????, ????????, ???????, ?? ???? ??????? ?? ??? ??? ??????? ????? ?? ????? ??????? ?? ???? ??? ?????????? ??????? ??? Fortunately, ???? ????? ???? ???? ???????-??????? ???? ?????? ????????? ?? ??? ???? ?? ??? ???? ?? ????? ?????? ???, ??????? C DLL ???? ??? ??????? ?????? ??? ?????? ?? ?? ?? C DLL ????? ???? ?????? ???? ??????? ??? ??? ?????? ????????? ?? ????? ?? ??? ??? ?? ??? ??? ??????? ???????, ???? ?? Visual Basic ?? ??????? ?? ????? ?? ?? ???? ??? ?? ???????? ?? ??? ??? ?? ?? ??? ????? ?? ???? ???? ??? Declare ????? ?? ??? ?? ????? ???? ?? ???????? ????? ??? ???? ??????? Visual Basic ??? ????? ???? ???
???? DLL ?? ??? ???? ?????? ?? ????????? ?? ????? ??? ?? ??? ???? ????? ?????? ?? ??????? ???? ?????????? ?? ?? ??? ????? ?? ????? ??? ?? ????? ???????? ?? ??? ??????? Visual Basic ???? ?????? ?????-???????? ?? ????? ???? ?? ??? binds ???????? ??? ?? ??? Contrast ???, ??? Declare ????? ???-????? ???? Furthermore, ?? ???? ???????? ??????? ?? ?? ????? ?? ???? DLL Visual Basic programmers ???? ?? ??? ???????? ?? ?? ??? ?????? ????????? ?????? ?? enumerations ?? ?????????? ??????? ?????? (UDTs) ???? ??????? ???????? ?? ??? ???????? ?? ??? Visual Basic friendly ??? ?????? ???? ?? ?????? ???? ???
??????? ???, ?????? ????????? ???? ???? ??? ???????? ??????? ???? (IDL) ?? ???????? ????? ???? (ODL) ??? ???? ?? ????????? ?? ????? ?? ??? ??? ?? ????????? ?? ????? ???? ??? MkTypLib.EXE ?? Visual Studio ?? ??? ??? MIDL.EXE ?????? ?? ???? ????? C++ ???? ??? ????? ?? ?????? ?????????, ??? ??? ?? ??????? ???? DLL ????????? ?? ??? ?????? ODL ??????? ???? ?? ????? ???????? ??? ?? ???? ?? ???? ?????? MIDL ?? ??? ?? ?? ???? ????????? ?? ??????? ?????
Step-by-Step ?????? ??? - DLL ?? ?????? ????????? ????? ????? C++ 5.0 ?????, ?? File|New ?? ??? ????? ????????? ??? ?? "Win32 ???????? ???? ?????????" ?? ??? ???? ?? "TLBSamp." ????????? ?? ??? ???: File|New ?? ??? ????? ????? ??? ?? "C++ ????? ????," "TLBSamp.c," ????? ??? ?? ??? ???? ?? ??? ?????? ??? 2 ??? ?? ????, ?? ?? ??? choose "??? ?????" ?? ????? ?????? ?? ??? ??? ????????
??????? ?? "TLBSamp.def" ?? "TLBSamp.odl" respectively ???? ????, TLBSamp.c ???? ?? ??? ????? ??? ??????:
#include <windows.h>
// MyDll_ReverseString -- Reverses the characters of a given string
void __stdcall MyDll_ReverseString(LPSTR lpString)
{
_strrev(lpString);
}
// MyDLL_Rotate -- Returns bit rotation of 32-bit integer value
int __stdcall MyDll_Rotate(int nVal, int nDirect, short iNumBits)
{
int nRet = 0;
if((iNumBits < 1) || (iNumBits > 31))
return nRet;
switch(nDirect)
{
case 0:
// Rotate nVal left by iNumBits
nRet = (((nVal) << (iNumBits)) |
((nVal) >> (32-(iNumBits))));
break;
case 1:
// Rotate nVal right by iNumBits
nRet = (((nVal) >> (iNumBits)) |
((nVal) << (32-(iNumBits))));
break;
}
return nRet;
}
?????? ??????? ????? ?????, ???? ?? ??? ????? TLBSamp.def ??? ??????:
LIBRARY TLBSamp
DESCRIPTION 'Microsoft KB Sample DLL'
EXPORTS
MyDll_ReverseString
MyDll_Rotate
TLBSamp.odl ???? ?? ??? ????? ?????? ???? ?????? ????????? ??? ???? ?????? ????? ????:
// This is the type library for TLBSamp.dll
[
// Use GUIDGEN.EXE to create the UUID that uniquely identifies
// this library on the user's system. NOTE: This must be done!!
uuid(F1B9E420-F306-11d1-996A-92FF02C40D32),
// This helpstring defines how the library will appear in the
// References dialog of VB.
helpstring("KB Sample: Make your C DLL More Accessible"),
// Assume standard English locale.
lcid(0x0409),
// Assign a version number to keep track of changes.
version(1.0)
]
library TLBSample
{
// Define an Enumeration to use in one of our functions.
typedef enum tagRotateDirection
{
tlbRotateLeft=0,
tlbRotateRight=1
}RotateDirection;
// Now define the module that will "declare" your C functions.
[
helpstring("Sample functions exported by TLibSamp.dll"),
version(1.0),
// Give the name of your DLL here.
dllname("TLBSamp.dll")
]
module MyDllFunctions
{
[
// Add a description for your function that the developer can
// read in the VB Object Browser.
helpstring("Returns the reverse of a given string."),
// Specify the actual DLL entry point for the function. Notice
// the entry field is like the Alias keyword in a VB Declare
// statement -- it allows you to specify a more friendly name
// for your exported functions.
entry("MyDll_ReverseString")
]
// The [in], [out], and [in, out] keywords tell the Automation
// client which direction parameters need to be passed. Some
// calls can be optimized if a function only needs a parameter
// to be passed one-way.
void __stdcall ReverseString([in, out] LPSTR sMyString);
[
helpstring("Rotates a Long value in the given direction."),
entry("MyDll_Rotate")
]
// Besides specifying more friendly names, you can specify a more
// friendly type for a parameter. Notice the Direction parameter
// has been declared with our enumeration. This gives the VB
// developer easy access to our constant values.
int __stdcall BitRotate([in] int Value,
[in] RotateDirection Direction,
[in] short Bits);
} // End of Module
}; // End of Library
"??? ???: ???????" ??? ?? ???? DLL ?? ?????? ????????? ????? ???? ?? ?????? ????? ?? ????? ??, ?? ??????? ?? ??? ???? Visual Basic ?????????? ?? ??? ?? DLL (TLBSamp.dll) ?? ????????? ?????? ????? ???: convenience ?? ??????, ?? ??? ??? ?? ???? ?????? ?? ??? ??? ???? DLL ??? ???? ?????? ????????? ?? ????? ???? ????? ?? ???? ??? ?? ???? ????? ?? Visual Basic ???????? ???? ?? ??? TLB ????? ?? ?????? ???? ?? ??? ??? ?? ?????
????? ?? ??? ????????? ??? ??? ?????? ?? ??? ???, ????? ????? ?? ???? ????:
File|New ?? ??? ????? ????? ??? ?? "??? ????," ????? ??? "TLBSamp.rc" ?? ??? ????, ?? ??? ?????? ????? ???? ???? ??? ????? ??? ????? ?????? ??????: 1 typelib TLBSamp.tlb ????? ?? ?????? ?? ???? DLL recompile ??? ?? ????? ??, ????????? ?? DLL (TLBSamp.dll); ???? ?? ??? ???? Visual Basic ?????????? ?? ??? ??? ??? ????? ????? ?? ???????? ????? Step-by-Step ?????? - Visual Basic ??????? ????????? DLL ?? ?????? ????????? ???????, Visual Basic 5.0 ????? ?? ?? ?? ???? ????????? ?????? Form1 ???????? ??? ?? ???? ??.. ????????? ???? ?? ??? ???? ?? ??? ?????? ?? ??? ?? ?????? ????? ????? ???, ?? ???? ??? ??????? ??? ????????? ???? ?????? ?? ??? ??? ????? ??, ?? ???? ?? ?????? ????????? (?? ???? DLL) ?????? ?? ???? ?? ??? ?? ?? ??? ??? ????? ??, ?? ??? ?????? Visual Basic ????? ???????? ??? ?? ????????? ??????? ???? ?? ??? ???? ??? ?????? ???? ????????? ???? ?? ???? ????????? ("KB ?? ?????: ???? C DLL ?? ????? ?????") ???????? ?? ???? ??? ??? ???? ??? ??, ?? ???? ??? ????? ????? ??? ????? ???????? ??????? ??? ???? ?? ??? F2 ????? ?????? ??? ???? ?? ???? ????????? (TLBSamp) ???? ?? ??? Visual Basic ????????? ??? ????? ??? ??, ?? ?? ?? ???? ?????? ?? ??? ?? ?? ?? ???? ??? ???? ???? ?? ?? ??? ????? ??? ??????? ??? Visual Basic ????? ?? ????? ???? ??? ???? ???? ?????? BitRotate ???? ?? ??? ???? ???????? ??? ???? ?? ??? ?? ?? ?????? Form1 ?? ?? CommandButton ?????? ?? ????? ??? ??? ????? ???? ?????? ?????:
Private Sub Command1_Click()
Dim n1 As Long, n2 As Long, nTmp As Long
Dim sTest As String, sMsg As String
sTest = "Hello World!"
n1 = 100
ReverseString sTest
sMsg = sTest & " | "
ReverseString sTest
sMsg = sMsg & sTest & vbCrLf
nTmp = BitRotate(n1, tlbRotateLeft, 2)
n2 = BitRotate(nTmp, tlbRotateRight, 2)
sMsg = sMsg & Str$(n1) & " : " & Str$(nTmp) & " : " & Str$(n2)
MsgBox sMsg
End Sub
?? IDE ??? vb5allB ????????? ?? ????? ?? ??? F5 ????? ?????? ????? ???: ??? ?? ?? ?????? ????? ??????? ???? ??, ?? ?? ???? ?? ??????? Visual Basic ???? DLL ???? ???? ????? ?? ????????? ???? ?? ?? ???? ?? ?? ????? ??? ?????????? ?? ???? ?????? ?? ?? ??? ???? ???? ??????? ????????? ?? ????? ?? ????? ODL ?? IDL ?? ?????? ?? ???????? ??????? ?? ??? ????? ????? ?????? ?? Microsoft ?????? ??????? (MSDN) ????????? ??? ?????:
??????: ??????????? ?? ???????? ????? ???? ?? ??? ????? ??????: ???????? ??????? ?? ?????? ???????????
???????? ??????? ?? ???, ????? ????? ?????? ?? Microsoft ???????? ??? ?????:
143258
(http://support.microsoft.com/kb/143258/EN-US/
)
: ???? ???????? ' ?? ' DLL Declarations ???? ?????? ????????? ??? ?????
122285
(http://support.microsoft.com/kb/122285/EN-US/
)
: ???? ?????? ???????????. dll ??. exe ????? ?? ??? ?????? ?? ??? ??? ?????
142840
(http://support.microsoft.com/kb/142840/EN-US/
)
: ?????? DLL ??????? ?? ??? Visual Basic ??????????
(?) Microsoft Corporation 1998, ??? ?????? ????????? Richard R. Taylor, Microsoft Corporation ?? ?????? ??????.
???? ???? ???? ??: Microsoft Visual Basic 5.0 Learning Edition Microsoft Visual Basic 5.0 Professional Edition Microsoft Visual Basic 6.0 Professional Edition Microsoft Visual C++ 5.0 Professional Edition Microsoft Visual Basic 5.0 Enterprise Edition kbhowto kbmt KB189133 KbMthi
???? ?????? ???????? ??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:
189133
(http://support.microsoft.com/kb/189133/en-us/
)
Was this information helpful?
How much effort did you personally put forth to use this article?
Tell us why and what can we do to improve this information
Thank you! Your feedback is used to help us improve our support content. For more assistance options, please visit the
Help and Support Home Page .
???? ?????? ???? ?????? ??????
??????
??? ?????? ??????? ????
???? ??????