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. C / C++ / MFC
  4. How to import VB Dll into VC++ Program and How to use functions from VB dll??

How to import VB Dll into VC++ Program and How to use functions from VB dll??

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpc++visual-studiotutorial
25 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.
  • S savitri

    Hii Ya it is loading dll properly because it is not giving error..i am checking conditions also.I send that part of code in last message please tell me what is wrong with my code.I am getting tension. Please give me some suggetions.please help me out. Thanks IN ADVANCE, Savitri:confused:

    S Offline
    S Offline
    SandipG
    wrote on last edited by
    #16

    Hi I just checked by creating ActiveXDLL project in VB. I don't think you can use it using LoadLibrary(). You have to use

       #import "YourDll.dll" no\_namespace
    

    Sample Code:

    CoInitialize(NULL);
    \_Class1Ptr class1; // Class1 is name of your class module
    class1.CreateInstance(\_\_uuidof(Class1));
    short i=10,k=20;
    int ans = class1->add(&i,&k);
    class1.Release();
    CoUninitialize();
    

    It works properly. I hope it helps

    Regards, Sandip.

    modified on Friday, August 22, 2008 8:11 AM

    S 1 Reply Last reply
    0
    • S SandipG

      savitri wrote:

      but in run time i am one error message box like send error and don't send..

      This error means your application is crashing.. did you verify that you are getting proper value for

      savitri wrote:

      ProcessingInformation = (ptr_func1)GetProcAddress(hLib,

      Regards, Sandip.

      S Offline
      S Offline
      savitri
      wrote on last edited by
      #17

      Hii Sandip, Ya when returning value from dll it is in -VE so it is giving error. I am not getting what is wrong with my program. please tell me. My code is like this: typedef BOOL (WINAPI* ptr_func1)(BSTR* bstr,BSTR* bstr1,BSTR* bstr2,BSTR* bstr3,BSTR* bstr4); ptr_func1 ProcessingInformation = NULL; HINSTANCE hLib; hLib = LoadLibrary(_T("C:\\Program Files\\Microsoft Visual Studio\\My Projects\\BoolDate\\SampleDll.dll")); if (hLib == NULL) { MessageBox(_T("Unable to load .dll"), NULL, MB_ICONERROR); } else { ProcessingInformation = (ptr_func1)GetProcAddress(hLib, _T("ProcessingInformation")); CString str; BSTR server,usr,pwd,Temp,Temp3; BOOL bstr; Temp=SysAllocString(L"21\8\2008"); str=Temp; MessageBox(str); Temp3=SysAllocString(L"21\7\2008"); str=Temp3; MessageBox(str); server=SysAllocString(L"savitri"); str=server; MessageBox(str); usr=SysAllocString(L"root"); str=usr; MessageBox(str); pwd=SysAllocString(L"base"); str=pwd; MessageBox(str); //bstr=TRUE; /*bstr=m_UserControl1.Processattendacne(&Temp,&Temp3,&server,&usr,&pwd); str.Format("%d",bstr); MessageBox(str);*/ m_Edit1="savitri"; m_Edit2="Base"; MessageBox("Gettting Value"); /* The actual call to the function contained in the dll */ bstr = ProcessingInformation(&Temp,&Temp3,&server,&usr,&pwd); MessageBox("Gettting BSTR Value"); str.Format("%d",bstr); MessageBox(str); SysFreeString(Temp); SysFreeString(Temp3); SysFreeString(server); SysFreeString(usr); SysFreeString(pwd); /* Release the Dll */ FreeLibrary(hLib); please help me out. Thanks in advance, Savitri

      S 1 Reply Last reply
      0
      • CPalliniC CPallini

        Could you please post your VB DLL code?

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        S Offline
        S Offline
        savitri
        wrote on last edited by
        #18

        Hii, My VB Code: Public Function ProcessingInformation(Date1 As String, Date2 As String, ServerName As String, Username As String, Password As String) As Boolean If Date1 <> "" Then ProcessingInformation = True Else ProcessingInformation = False End If End Function this is dll called SampleDll and module FunctionClass please tell me how to use this dll in VC++..please this is very fewer for me. Thanks in advance, Savitri

        1 Reply Last reply
        0
        • S savitri

          Hii Sandip, Ya when returning value from dll it is in -VE so it is giving error. I am not getting what is wrong with my program. please tell me. My code is like this: typedef BOOL (WINAPI* ptr_func1)(BSTR* bstr,BSTR* bstr1,BSTR* bstr2,BSTR* bstr3,BSTR* bstr4); ptr_func1 ProcessingInformation = NULL; HINSTANCE hLib; hLib = LoadLibrary(_T("C:\\Program Files\\Microsoft Visual Studio\\My Projects\\BoolDate\\SampleDll.dll")); if (hLib == NULL) { MessageBox(_T("Unable to load .dll"), NULL, MB_ICONERROR); } else { ProcessingInformation = (ptr_func1)GetProcAddress(hLib, _T("ProcessingInformation")); CString str; BSTR server,usr,pwd,Temp,Temp3; BOOL bstr; Temp=SysAllocString(L"21\8\2008"); str=Temp; MessageBox(str); Temp3=SysAllocString(L"21\7\2008"); str=Temp3; MessageBox(str); server=SysAllocString(L"savitri"); str=server; MessageBox(str); usr=SysAllocString(L"root"); str=usr; MessageBox(str); pwd=SysAllocString(L"base"); str=pwd; MessageBox(str); //bstr=TRUE; /*bstr=m_UserControl1.Processattendacne(&Temp,&Temp3,&server,&usr,&pwd); str.Format("%d",bstr); MessageBox(str);*/ m_Edit1="savitri"; m_Edit2="Base"; MessageBox("Gettting Value"); /* The actual call to the function contained in the dll */ bstr = ProcessingInformation(&Temp,&Temp3,&server,&usr,&pwd); MessageBox("Gettting BSTR Value"); str.Format("%d",bstr); MessageBox(str); SysFreeString(Temp); SysFreeString(Temp3); SysFreeString(server); SysFreeString(usr); SysFreeString(pwd); /* Release the Dll */ FreeLibrary(hLib); please help me out. Thanks in advance, Savitri

          S Offline
          S Offline
          SandipG
          wrote on last edited by
          #19

          Did you check my post above Import[^] I think you cant use LoadLibrary(). I have given sample code in post above.

          Regards, Sandip.

          S 1 Reply Last reply
          0
          • S SandipG

            Hi I just checked by creating ActiveXDLL project in VB. I don't think you can use it using LoadLibrary(). You have to use

               #import "YourDll.dll" no\_namespace
            

            Sample Code:

            CoInitialize(NULL);
            \_Class1Ptr class1; // Class1 is name of your class module
            class1.CreateInstance(\_\_uuidof(Class1));
            short i=10,k=20;
            int ans = class1->add(&i,&k);
            class1.Release();
            CoUninitialize();
            

            It works properly. I hope it helps

            Regards, Sandip.

            modified on Friday, August 22, 2008 8:11 AM

            S Offline
            S Offline
            savitri
            wrote on last edited by
            #20

            Hi Sandip, I used like this but i am getting errors..I am writting like this: ::CoInitialize(NULL); //note this change after taking out the no_namespace macro //if there is no namespace then also the progid has to be __uuidof(VbDll::CVbDll) like this SampleDll::_FunctionClass sample; HRESULT hr=sample.CreateInstance(__uuidof(SampleDll::_FunctionClass)); //here the progid is VbDll::CVbDll) //not just CVbDll //sample.AddRef(); BSTR server,usr,pwd,Temp,Temp3; BOOL bstr; Temp=SysAllocString(L"21\8\2008"); str=Temp; MessageBox(str); Temp3=SysAllocString(L"21\7\2008"); str=Temp3; MessageBox(str); server=SysAllocString(L"savitri"); str=server; MessageBox(str); usr=SysAllocString(L"root"); str=usr; MessageBox(str); pwd=SysAllocString(L"base"); str=pwd; MessageBox(str); BOOL bstrMyString;//=TRUE; //check for the instance bstrMyString=sample.ProcessingInformation(&Temp,&Temp3,&server,&usr,&pwd); str.Format("%d\n", bstrMyString); MessageBox(str, "MyString aus VB", MB_OK); sample.Release(); ::CoUninitialize(); It is giving errors... 1. C:\Program Files\Microsoft Visual Studio\My Projects\UseVbDll\UseVbDllDlg.cpp(194) : error C2259: '_FunctionClass' : cannot instantiate abstract class due to following members: c:\program files\microsoft visual studio\my projects\usevbdll\debug\sampledll.tlh(34) : see declaration of '_FunctionClass' 2.C:\Program Files\Microsoft Visual Studio\My Projects\UseVbDll\UseVbDllDlg.cpp(194) : error C2259: '_FunctionClass' : cannot instantiate abstract class due to following members: c:\program files\microsoft visual studio\my projects\usevbdll\debug\sampledll.tlh(34) : see declaration of '_FunctionClass' 3.C:\Program Files\Microsoft Visual Studio\My Projects\UseVbDll\UseVbDllDlg.cpp(195) : error C2039: 'CreateInstance' : is not a member of '_FunctionClass' c:\program files\microsoft visual studio\my projects\usevbdll\debug\sampledll.tlh(34) : see declaration of '_FunctionClass' My Dll is like this // c:\program files\microsoft visual studio\my projects\usevbdll\debug\SampleDll.tlh // // C++ source equivalent of Win32 type library C:\Program Files\Microsoft Visual Studio\My Projects\BoolDate\SampleDll.dll // compiler-generated file created 08/22/08 at 17:31:22 - DO NOT EDIT! #pragma once #pragma pack(push, 8) #include namespace SampleDll { struct __declspec(uuid("a3105692-d6d7-41e0-8d8c-f4ab326fa2f4")) /* dual interface */ _FunctionClass; struct /*

            S 1 Reply Last reply
            0
            • S savitri

              Hi Sandip, I used like this but i am getting errors..I am writting like this: ::CoInitialize(NULL); //note this change after taking out the no_namespace macro //if there is no namespace then also the progid has to be __uuidof(VbDll::CVbDll) like this SampleDll::_FunctionClass sample; HRESULT hr=sample.CreateInstance(__uuidof(SampleDll::_FunctionClass)); //here the progid is VbDll::CVbDll) //not just CVbDll //sample.AddRef(); BSTR server,usr,pwd,Temp,Temp3; BOOL bstr; Temp=SysAllocString(L"21\8\2008"); str=Temp; MessageBox(str); Temp3=SysAllocString(L"21\7\2008"); str=Temp3; MessageBox(str); server=SysAllocString(L"savitri"); str=server; MessageBox(str); usr=SysAllocString(L"root"); str=usr; MessageBox(str); pwd=SysAllocString(L"base"); str=pwd; MessageBox(str); BOOL bstrMyString;//=TRUE; //check for the instance bstrMyString=sample.ProcessingInformation(&Temp,&Temp3,&server,&usr,&pwd); str.Format("%d\n", bstrMyString); MessageBox(str, "MyString aus VB", MB_OK); sample.Release(); ::CoUninitialize(); It is giving errors... 1. C:\Program Files\Microsoft Visual Studio\My Projects\UseVbDll\UseVbDllDlg.cpp(194) : error C2259: '_FunctionClass' : cannot instantiate abstract class due to following members: c:\program files\microsoft visual studio\my projects\usevbdll\debug\sampledll.tlh(34) : see declaration of '_FunctionClass' 2.C:\Program Files\Microsoft Visual Studio\My Projects\UseVbDll\UseVbDllDlg.cpp(194) : error C2259: '_FunctionClass' : cannot instantiate abstract class due to following members: c:\program files\microsoft visual studio\my projects\usevbdll\debug\sampledll.tlh(34) : see declaration of '_FunctionClass' 3.C:\Program Files\Microsoft Visual Studio\My Projects\UseVbDll\UseVbDllDlg.cpp(195) : error C2039: 'CreateInstance' : is not a member of '_FunctionClass' c:\program files\microsoft visual studio\my projects\usevbdll\debug\sampledll.tlh(34) : see declaration of '_FunctionClass' My Dll is like this // c:\program files\microsoft visual studio\my projects\usevbdll\debug\SampleDll.tlh // // C++ source equivalent of Win32 type library C:\Program Files\Microsoft Visual Studio\My Projects\BoolDate\SampleDll.dll // compiler-generated file created 08/22/08 at 17:31:22 - DO NOT EDIT! #pragma once #pragma pack(push, 8) #include namespace SampleDll { struct __declspec(uuid("a3105692-d6d7-41e0-8d8c-f4ab326fa2f4")) /* dual interface */ _FunctionClass; struct /*

              S Offline
              S Offline
              SandipG
              wrote on last edited by
              #21

              savitri wrote:

              HRESULT hr=sample.CreateInstance(__uuidof(SampleDll::_FunctionClass)); //here the progid is VbDll::CVbDll)

              Dont pass _FunctinClass use SampleDll::FunctionClass. Also You are using SampleDll::_FunctionClass sample; Here you need use SampleDll::_FunctionClassPtr sample; Just check my post again. BTW Use Code block button below posting area for code blocks it is very difficult to read your code otherwise.

              Regards, Sandip.

              modified on Friday, August 22, 2008 8:17 AM

              S 1 Reply Last reply
              0
              • S SandipG

                Did you check my post above Import[^] I think you cant use LoadLibrary(). I have given sample code in post above.

                Regards, Sandip.

                S Offline
                S Offline
                savitri
                wrote on last edited by
                #22

                Hii.. I am doing as you told me in previous post.please check your mail once or check my reply to your post import.please tell me thanks, savitri

                S 1 Reply Last reply
                0
                • S savitri

                  Hii.. I am doing as you told me in previous post.please check your mail once or check my reply to your post import.please tell me thanks, savitri

                  S Offline
                  S Offline
                  SandipG
                  wrote on last edited by
                  #23

                  Please follow the same thread above. I have replied to you pointing out the errors. Please check.

                  Regards, Sandip.

                  1 Reply Last reply
                  0
                  • S SandipG

                    savitri wrote:

                    HRESULT hr=sample.CreateInstance(__uuidof(SampleDll::_FunctionClass)); //here the progid is VbDll::CVbDll)

                    Dont pass _FunctinClass use SampleDll::FunctionClass. Also You are using SampleDll::_FunctionClass sample; Here you need use SampleDll::_FunctionClassPtr sample; Just check my post again. BTW Use Code block button below posting area for code blocks it is very difficult to read your code otherwise.

                    Regards, Sandip.

                    modified on Friday, August 22, 2008 8:17 AM

                    S Offline
                    S Offline
                    savitri
                    wrote on last edited by
                    #24

                    Hii I did as u told but no change in it..i am fed of this dll.. thanks for response, savitri

                    S 1 Reply Last reply
                    0
                    • S savitri

                      Hii I did as u told but no change in it..i am fed of this dll.. thanks for response, savitri

                      S Offline
                      S Offline
                      SandipG
                      wrote on last edited by
                      #25

                      I don't know it should work All the best :)

                      Regards, Sandip.

                      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