Use DLL in VBasic
-
How can i use a dll in VB which is written in VC++ ??? please help me as soon as possible. thanks ;) el hombre es libre cada vez que elige y eso es lo que lo hace libre
-
How can i use a dll in VB which is written in VC++ ??? please help me as soon as possible. thanks ;) el hombre es libre cada vez que elige y eso es lo que lo hace libre
-
Hello, Add a declaration of functions which has public scope(those which you want to use in your VB project). Or you can add the reference of your DLL in Project/Reference by choosing it. Have fun.;) Regards, Vilas Shewale
Firstly, Thanks for your fast reply. I´m a beginner in both lenguages, VB and English too. So, i tried by the Reference method ,but i couldn´t do , because when i select the DLL VB show me a message :"Can´t add the reference to the specified File " The DLL isn´t registred, Can be the problem? how can i do the declaration? el hombre es libre cada vez que elige y eso es lo que lo hace libre
-
Firstly, Thanks for your fast reply. I´m a beginner in both lenguages, VB and English too. So, i tried by the Reference method ,but i couldn´t do , because when i select the DLL VB show me a message :"Can´t add the reference to the specified File " The DLL isn´t registred, Can be the problem? how can i do the declaration? el hombre es libre cada vez que elige y eso es lo que lo hace libre
Hi You are using a simple dll, not a COM dll. When you are trying import a basic dll wihtout interface, you can´t reference using your VB tool development. You need inport it by code. VB.NET sample: -------------------------------- _ Public Shared Function FunctionName(ByRef Param1 As Integer, _ ByRef Param2 As String, _ ByVal Param3 As Integer) As Long End Function -------------------------------- Regards "On the 8th day, God started debugging"
-
Hi You are using a simple dll, not a COM dll. When you are trying import a basic dll wihtout interface, you can´t reference using your VB tool development. You need inport it by code. VB.NET sample: -------------------------------- _ Public Shared Function FunctionName(ByRef Param1 As Integer, _ ByRef Param2 As String, _ ByVal Param3 As Integer) As Long End Function -------------------------------- Regards "On the 8th day, God started debugging"
i´m using VB6, and It don´t have "Shared". I only want use a simple DLL from this example :http://www.codeproject.com/dll/BeginnerDLL.asp But I don´t know how import the dll, and where i have to copy the dll (because i don´t want registrer it ):confused: i´m so confused el hombre es libre cada vez que elige y eso es lo que lo hace libre
-
i´m using VB6, and It don´t have "Shared". I only want use a simple DLL from this example :http://www.codeproject.com/dll/BeginnerDLL.asp But I don´t know how import the dll, and where i have to copy the dll (because i don´t want registrer it ):confused: i´m so confused el hombre es libre cada vez que elige y eso es lo que lo hace libre
Martin_Viet wrote: But I don´t know how import the dll, and where i have to copy the dll (because i don´t want registrer it ) You can place the .dll in whatever directory you want it in, however you do need to register the .dll. Go to a command prompt and change the directory to the location of the .dll. Once there type (where myFile is the name of the .dll):
regsvr32 myFile.dll
-Nick Parker
-
Martin_Viet wrote: But I don´t know how import the dll, and where i have to copy the dll (because i don´t want registrer it ) You can place the .dll in whatever directory you want it in, however you do need to register the .dll. Go to a command prompt and change the directory to the location of the .dll. Once there type (where myFile is the name of the .dll):
regsvr32 myFile.dll
-Nick Parker
But I found it: If you do not specify a path for libname, Visual Basic will search for the file in the following order: 1)Directory containing the .exe file 2)Current directory Windows system directory (often but not necessarily Windows\System) 3)Windows directory (not necessarily \Windows) 4)Path environment variable " [Visual Studio 6.0 Help] So i´m trying to do this :
Public Declare Function SayHello Lib "MyDLL.dll" () As Boolean
But a message error appeared X| el hombre es libre cada vez que elige y eso es lo que lo hace libre -
But I found it: If you do not specify a path for libname, Visual Basic will search for the file in the following order: 1)Directory containing the .exe file 2)Current directory Windows system directory (often but not necessarily Windows\System) 3)Windows directory (not necessarily \Windows) 4)Path environment variable " [Visual Studio 6.0 Help] So i´m trying to do this :
Public Declare Function SayHello Lib "MyDLL.dll" () As Boolean
But a message error appeared X| el hombre es libre cada vez que elige y eso es lo que lo hace libreHi I´ll explain in spanish, becase I think, you'll understand better the explanation: 1.Necesitas registrar la dll en el sistema, para ello copia la dll al winnt\system32 y desde ahí ejecuta "regsvr32 TuLibreria.dll" 2.Una vez registrado abre el VB y en el menu busca "Proyecto/Referencias" que abrira una ventana donde puedes examinar y seleccionar la dll. 3.Una vez referenciada, solo has de instanciarla por codigo, como por ejemplo: Dim ObjDLL As New PuntoDeEntradaDeLaDLL() Regards and good luck. "On the 8th day, God started debugging"
-
But I found it: If you do not specify a path for libname, Visual Basic will search for the file in the following order: 1)Directory containing the .exe file 2)Current directory Windows system directory (often but not necessarily Windows\System) 3)Windows directory (not necessarily \Windows) 4)Path environment variable " [Visual Studio 6.0 Help] So i´m trying to do this :
Public Declare Function SayHello Lib "MyDLL.dll" () As Boolean
But a message error appeared X| el hombre es libre cada vez que elige y eso es lo que lo hace libreMartin_Viet wrote: So i´m trying to do this : Public Declare Function SayHello Lib "MyDLL.dll" () As Boolean But a message error appeared The .dll still needs to be registered, then just specify the path to the file. Just by specifying the file's path does not mean you have registered the file, these are two different things. -Nick Parker
-
Martin_Viet wrote: So i´m trying to do this : Public Declare Function SayHello Lib "MyDLL.dll" () As Boolean But a message error appeared The .dll still needs to be registered, then just specify the path to the file. Just by specifying the file's path does not mean you have registered the file, these are two different things. -Nick Parker
Hello, You can try this. Register your DLL with regsvr32 utility. 1> Goto Start Menu. Press run. Type regsvr32 "path of DLL". And just press Ok. You will get the message of registration by Windows. 2> Or, Double Click on the DLL. It will ask you about the program to be open. Choose the regsvr32.exe from Windows directory. Press ok. Windows will register your DLL automatically. Make sure that you have to place your DLL in the directory which has your project through which you are accessing the DLL code. Regards, ;) Vilas Shewale
-
Martin_Viet wrote: But I don´t know how import the dll, and where i have to copy the dll (because i don´t want registrer it ) You can place the .dll in whatever directory you want it in, however you do need to register the .dll. Go to a command prompt and change the directory to the location of the .dll. Once there type (where myFile is the name of the .dll):
regsvr32 myFile.dll
-Nick Parker
very I am pleaced It has been eassier on this way, which determines that I am going to have to continue practicing languages both (English and VB )thanks and greetings :-D el hombre es libre cada vez que elige y eso es lo que lo hace libre
-
i´m using VB6, and It don´t have "Shared". I only want use a simple DLL from this example :http://www.codeproject.com/dll/BeginnerDLL.asp But I don´t know how import the dll, and where i have to copy the dll (because i don´t want registrer it ):confused: i´m so confused el hombre es libre cada vez que elige y eso es lo que lo hace libre
This is kind of lengthy... but this is how i do it. First, create a dll project in vcc. Select MFC AppWizard(DLL). Select Regular DLL. Does'nt matter whether MFC is static or shared. Create a .cpp file for your function you want to call. You will have to create "C" style function because you cannot do external linkage to vb with C++ classes. This example is a function called Function123. It takes a string you can modify and returns a UINT. prototype: extern "C" UINT __stdcall Function123 (LPSTR lpszBenefits); the body looks like this: extern "C" UINT __stdcall Function123(LPSTR lpszBenefits) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); // This line is important!!! // do something return someUINT; } Now find the .def file that vc created. It should be under source files where the rest of the cpp files are. Add the following entry to the file: Function123 @1 The @1 indicates that this is function #1 to be exported. If you add more functions then they should be as @2,@3 etc. Compile your project and produce the DLL. Now, in VB: Add this line at the top of a module file: Private Declare Function vbfunctionname Lib "EChartPatients.dll" Alias "Function123" (ByVal strName As String) As Long Now in your module to use this function: ... dim x as integer dim y as string x= vbfunctionname(y) ... The DLL you created does not have to be linked to the vb exe in any way except that it has to be in the executable path, or, you have to hardcode the path + name in the vb declare statement. Warning: Initialize your vb string to the max length required prior to sending it into the dll.