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

    Hi EveryOne, I am doing one VC++ Program in that i want to insert VB Dll. i am importing dll in stdafx.h file like this #import "C:\Program Files\Microsoft Visual Studio\My Projects\BoolDate\SampleDll.dll" In VB Dll i am having one function called ProcessingInformation with 5 string type variables and return type is boolean. After this i am adding one button in that button function i want access processinformation function but when i am accessing then it is giving error like processinformation is undefined declaration. Please tell me how to use dll functions in my program i tried but i am getting solution.i used one way which i got from codeproject only but in that midl not found error is coming in command prompt. Please give me some suggestions...HELP ME OUT... Thanks in ADVANCE, Savitri

    H Offline
    H Offline
    Hamid Taebi
    wrote on last edited by
    #2

    For using dll on the c++ you need to use of LoadLibrary and then use of GetProcAddress.

    CPalliniC 1 Reply Last reply
    0
    • S savitri

      Hi EveryOne, I am doing one VC++ Program in that i want to insert VB Dll. i am importing dll in stdafx.h file like this #import "C:\Program Files\Microsoft Visual Studio\My Projects\BoolDate\SampleDll.dll" In VB Dll i am having one function called ProcessingInformation with 5 string type variables and return type is boolean. After this i am adding one button in that button function i want access processinformation function but when i am accessing then it is giving error like processinformation is undefined declaration. Please tell me how to use dll functions in my program i tried but i am getting solution.i used one way which i got from codeproject only but in that midl not found error is coming in command prompt. Please give me some suggestions...HELP ME OUT... Thanks in ADVANCE, Savitri

      CPalliniC Online
      CPalliniC Online
      CPallini
      wrote on last edited by
      #3

      savitri wrote:

      I am doing one VC++ Program in that i want to insert VB Dll

      The first good question maybe: why do I need such a thing? :-D

      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]

      In testa che avete, signor di Ceprano?

      S 1 Reply Last reply
      0
      • H Hamid Taebi

        For using dll on the c++ you need to use of LoadLibrary and then use of GetProcAddress.

        CPalliniC Online
        CPalliniC Online
        CPallini
        wrote on last edited by
        #4

        That's explicit DLL loading. You should mention also the implicit one. :)

        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]

        In testa che avete, signor di Ceprano?

        H 1 Reply Last reply
        0
        • CPalliniC CPallini

          That's explicit DLL loading. You should mention also the implicit one. :)

          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]

          H Offline
          H Offline
          Hamid Taebi
          wrote on last edited by
          #5

          I think he wants to load dlls on the c++. :)

          CPalliniC 1 Reply Last reply
          0
          • CPalliniC CPallini

            savitri wrote:

            I am doing one VC++ Program in that i want to insert VB Dll

            The first good question maybe: why do I need such a thing? :-D

            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
            #6

            Hii Thanks for replying..I am having one DLL in VB for my project Concern. But i dont how to import DLL's in VC++.When i am doing like that what i mentioned in last message it is not possible to get functions from dll. So please will you tell me how can i get the functions from the VB dll to vc program. Please help me out I am trying from two days but i am not getting solution please tell me..I am using loadlibrary and getprocaddress 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); /* 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 tell me what is wrong with this code.Now i am not getting any errors in compiling time but in run time i am one error message box like send error and don't send.. Please Help me.I need your help very much. Thanks In Advance, Savitri

            _ CPalliniC S 3 Replies Last reply
            0
            • H Hamid Taebi

              I think he wants to load dlls on the c++. :)

              CPalliniC Online
              CPalliniC Online
              CPallini
              wrote on last edited by
              #7

              Hamid. wrote:

              I think he wants to load dlls on the c++

              That's true. Anyway, you know, there are two ways to do it (and implicit DLL load is the load-time linking with the DLL). [added] Well, maybe I got you: for a VB DLL you haven't neither the .lib nor the the .h file needed to compiler your project for implicit loading (and I don't remember if #import directive may help). [/added] :)

              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]

              modified on Friday, August 22, 2008 6:40 AM

              In testa che avete, signor di Ceprano?

              H 1 Reply Last reply
              0
              • S savitri

                Hii Thanks for replying..I am having one DLL in VB for my project Concern. But i dont how to import DLL's in VC++.When i am doing like that what i mentioned in last message it is not possible to get functions from dll. So please will you tell me how can i get the functions from the VB dll to vc program. Please help me out I am trying from two days but i am not getting solution please tell me..I am using loadlibrary and getprocaddress 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); /* 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 tell me what is wrong with this code.Now i am not getting any errors in compiling time but in run time i am one error message box like send error and don't send.. Please Help me.I need your help very much. Thanks In Advance, Savitri

                _ Offline
                _ Offline
                _AnsHUMAN_
                wrote on last edited by
                #8

                Does the DLL load successfully? Also did you check that functions that you are calling are exported from the DLL BTW on which line do you encounter the crash

                Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

                S 1 Reply Last reply
                0
                • S savitri

                  Hii Thanks for replying..I am having one DLL in VB for my project Concern. But i dont how to import DLL's in VC++.When i am doing like that what i mentioned in last message it is not possible to get functions from dll. So please will you tell me how can i get the functions from the VB dll to vc program. Please help me out I am trying from two days but i am not getting solution please tell me..I am using loadlibrary and getprocaddress 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); /* 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 tell me what is wrong with this code.Now i am not getting any errors in compiling time but in run time i am one error message box like send error and don't send.. Please Help me.I need your help very much. Thanks In Advance, Savitri

                  CPalliniC Online
                  CPalliniC Online
                  CPallini
                  wrote on last edited by
                  #9

                  Did you try to debug? At what line the error occurs? Do you have the source of the VB DLL?

                  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]

                  In testa che avete, signor di Ceprano?

                  S 1 Reply Last reply
                  0
                  • S savitri

                    Hii Thanks for replying..I am having one DLL in VB for my project Concern. But i dont how to import DLL's in VC++.When i am doing like that what i mentioned in last message it is not possible to get functions from dll. So please will you tell me how can i get the functions from the VB dll to vc program. Please help me out I am trying from two days but i am not getting solution please tell me..I am using loadlibrary and getprocaddress 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); /* 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 tell me what is wrong with this code.Now i am not getting any errors in compiling time but in run time i am one error message box like send error and don't send.. Please Help me.I need your help very much. Thanks In Advance, Savitri

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

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

                      Did you try to debug? At what line the error occurs? Do you have the source of the VB DLL?

                      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
                      #11

                      Hii I am getting error when the cursor is on the function called..ya i am having vb Dll code of 5 line..it is test dll..so i am testing whether vb dll can i insert properly or not in vc program.please tell me how come out from this problem. Please give me some suggetions.please help me out. Thanks IN ADVANCE, Savitri

                      CPalliniC S 2 Replies Last reply
                      0
                      • _ _AnsHUMAN_

                        Does the DLL load successfully? Also did you check that functions that you are calling are exported from the DLL BTW on which line do you encounter the crash

                        Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

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

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

                          Hii I am getting error when the cursor is on the function called..ya i am having vb Dll code of 5 line..it is test dll..so i am testing whether vb dll can i insert properly or not in vc program.please tell me how come out from this problem. Please give me some suggetions.please help me out. Thanks IN ADVANCE, Savitri

                          CPalliniC Online
                          CPalliniC Online
                          CPallini
                          wrote on last edited by
                          #13

                          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]

                          In testa che avete, signor di Ceprano?

                          S 1 Reply Last reply
                          0
                          • CPalliniC CPallini

                            Hamid. wrote:

                            I think he wants to load dlls on the c++

                            That's true. Anyway, you know, there are two ways to do it (and implicit DLL load is the load-time linking with the DLL). [added] Well, maybe I got you: for a VB DLL you haven't neither the .lib nor the the .h file needed to compiler your project for implicit loading (and I don't remember if #import directive may help). [/added] :)

                            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]

                            modified on Friday, August 22, 2008 6:40 AM

                            H Offline
                            H Offline
                            Hamid Taebi
                            wrote on last edited by
                            #14

                            Except this, use of windows api's on other languages is difficult c++.

                            1 Reply Last reply
                            0
                            • S savitri

                              Hii I am getting error when the cursor is on the function called..ya i am having vb Dll code of 5 line..it is test dll..so i am testing whether vb dll can i insert properly or not in vc program.please tell me how come out from this problem. Please give me some suggetions.please help me out. Thanks IN ADVANCE, Savitri

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

                              I dont know much about VB But i think the function you exporting should be defined in Class Module. are you doing that. You can open your dll in "Dependency walker" and check if you can see your function there.

                              Regards, Sandip.

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