Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Use DLL in VBasic

Use DLL in VBasic

Scheduled Pinned Locked Moved Visual Basic
questionc++help
12 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Martin_Viet
    wrote on last edited by
    #1

    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

    V 1 Reply Last reply
    0
    • M Martin_Viet

      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

      V Offline
      V Offline
      Villly
      wrote on last edited by
      #2

      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

      M 1 Reply Last reply
      0
      • V Villly

        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

        M Offline
        M Offline
        Martin_Viet
        wrote on last edited by
        #3

        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

        O 1 Reply Last reply
        0
        • M Martin_Viet

          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

          O Offline
          O Offline
          Oscar Martin
          wrote on last edited by
          #4

          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"

          M 1 Reply Last reply
          0
          • O Oscar Martin

            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"

            M Offline
            M Offline
            Martin_Viet
            wrote on last edited by
            #5

            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

            N R 2 Replies Last reply
            0
            • M Martin_Viet

              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

              N Offline
              N Offline
              Nick Parker
              wrote on last edited by
              #6

              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

              M 2 Replies Last reply
              0
              • N 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

                M Offline
                M Offline
                Martin_Viet
                wrote on last edited by
                #7

                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

                O N 2 Replies Last reply
                0
                • M Martin_Viet

                  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

                  O Offline
                  O Offline
                  Oscar Martin
                  wrote on last edited by
                  #8

                  Hi 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"

                  1 Reply Last reply
                  0
                  • M Martin_Viet

                    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

                    N Offline
                    N Offline
                    Nick Parker
                    wrote on last edited by
                    #9

                    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

                    V 1 Reply Last reply
                    0
                    • N 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

                      V Offline
                      V Offline
                      Villly
                      wrote on last edited by
                      #10

                      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

                      1 Reply Last reply
                      0
                      • N 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

                        M Offline
                        M Offline
                        Martin_Viet
                        wrote on last edited by
                        #11

                        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

                        1 Reply Last reply
                        0
                        • M Martin_Viet

                          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

                          R Offline
                          R Offline
                          Rob McBean
                          wrote on last edited by
                          #12

                          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.

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups