Ask Experts Questions for FREE Help!
  Advanced
Register  |  Log in  
   Ask    
 Answer  
  Help  

Ask QuestionsprogressAnswer QuestionsprogressBuild ReputationprogressBecome an Expert
 
Free Answers in 3 Easy Steps

Register Now
3 Steps

At Ask Me Help Desk you can ask questions in any topic and have them answered for free by our experts. To ask questions or participate in answering them you must register for a free account. By registering you will be able to:
  • Get free answers from experts in any of our 300+ topics.
  • Accept money for answers that you provide.
  • Communicate privately with other members (PM).
  • See fewer ads.

Home > Computers & Technology > Internet & the Web   »   Accessing VB dll from VC++

 
Question Tools Search this Question Display Modes
Question
 
 
#1  
Old Jan 25, 2006, 04:19 AM
john_christopher_s
New Member
john_christopher_s is offline
 
Join Date: Jan 2006
Posts: 6
john_christopher_s See this member's comment history on his/her Profile page.
Accessing VB dll from VC++

I have developped windows dll from VB. (The site http://www.windowsdevcenter.com/pub/...ll.html?page=3 gives a way to generate windows dll from VB). when I try to access it from VC++, it gives run time error as access violation. But I can access it from VB client

If anybody knows the solution to access the DLL in VC++ , created from VB please let me know

Thanks

Reply With Quote
 
     

Answers
 
 
Old Jan 28, 2006, 09:10 PM   #2  
Ademan
Junior Member
Ademan is offline
 
Join Date: Jan 2006
Posts: 42
Ademan See this member's comment history on his/her Profile page.
Well, i figure theres gotta be plenty at google, but regardless i'll give my best educated guess. But first you need to help us all out. How are you linking with the dll? If you're using some built in IDE functionality, you may need to link with it dynamically. If youre using a static lib (that contains all of the symbols for the dll) then you again, might want to try dynamic linking. Finnaly, depending on the version of vb (then again maybe not) there very well may be a dll that you need to link with to allow vb dlls/apps to work (i know there is for at least the older versions of vb, i dont know about newer though) also make sure you've created a win32 program not a win32 console program. The win32 console program PROBABLY won't link with all the necessary libraries to make the win32 API work

hope that helps
-Dan

EDIT: ah yes, also beware what directory your dll is in, it needs to be either in the windows/system32 folder, or in the program's directory. Now be careful though, msvc has been considered 'wierd' by many, because In DEBUG mode the program's directory is actually the project directory, as opposed to the project directory/DEBUG
  Reply With Quote
 
     
 
 
Old Jan 29, 2006, 07:20 PM   #3  
john_christopher_s
New Member
john_christopher_s is offline
 
Join Date: Jan 2006
Posts: 6
john_christopher_s See this member's comment history on his/her Profile page.
Thanks for your kind reply. Actually I have an executable, which is created in VC++. (I dont know what kind this source is , i.e., win32 console or win32 program or any other). this program will reads dll and do the operations on the particular functions, (the function names thay gave). if we create dll from vc++ then it works fine, but if we create from VB it tells access violation error.

But Loadlibrary works and getprocaddress also works fine. while calling function it tells error. please if you have any example program help to me.

thanks,
  Reply With Quote
 
     
 
 
Old Jan 29, 2006, 07:54 PM   #4  
Ademan
Junior Member
Ademan is offline
 
Join Date: Jan 2006
Posts: 42
Ademan See this member's comment history on his/her Profile page.
Hrm, well if load library doesnt result in any sort of error then I don't know what to say. LoadLibrary returns NULL if it fails, I don't KNOW if you're checking for that or not, but you should be (and it seems you are). However, I know at least in the case of C++ if a function belongs to a class, and you export that function, when you use GetProcAddress() you dont use the string you would expect, as opposed to say "CFoo::Bar()" it would be something like "ZCFOO@@!BarV" (of course that's entirely hypothetical) but thats referred to as "name mangling" and its how c++ deals with overloaded functions and classes being exported to dlls. I would assume (since to the best of my knowledge VB supports operator overloading) that VB uses name mangling as well.

I'm sorry i'm not of more help. anyways here are a few links that might help

http://www.daniweb.com/techtalkforums/thread17300.html


http://support.microsoft.com/default.aspx?kbid=194873

hope that helps
-Dan
  Reply With Quote
 
     
 
 
Old Jan 30, 2006, 11:36 PM   #5  
john_christopher_s
New Member
john_christopher_s is offline
 
Join Date: Jan 2006
Posts: 6
john_christopher_s See this member's comment history on his/her Profile page.
Thanks for your help. I have checked the two dlls (from VC++ and VB). I got the same function names. while in VB it gives additional four functions (like DllRegisterServer). and Im not at all able to call that function from VC++. actually LoadLibrary loads that dll and getProcAddress takes the corresponding function. (I have debugged it). But when I try to call that function it says access violation error.
I have debugged it. The control will be passed to the corresponding function, inside that function only I got that error, if i call that same function in VB client I didnt get that error. It works fine for VB client.
I have used only generic data types like integer.
If you got any idea please share with me

Thank you,
  Reply With Quote
 
     
 
 
Old Jan 31, 2006, 08:20 AM   #6  
Ademan
Junior Member
Ademan is offline
 
Join Date: Jan 2006
Posts: 42
Ademan See this member's comment history on his/her Profile page.
Yeah it sounds to me like the VBdll has an additional dependancy, like ActiveX or something, I really don't know enough about how VB Dlls work. But if GetProcAddress returns valid addresses and the access violation occurrs INSIDE the function that you call. I'm willing to bet money it has to do with an external dependancy.

cheers
-Dan
  Reply With Quote
 
     
 
 
Old Feb 10, 2006, 01:39 AM   #7  
esteve
New Member
esteve is offline
 
Join Date: Feb 2006
Posts: 1
esteve See this member's comment history on his/her Profile page.
Quote:
Originally Posted by john_christopher_s
I have developped windows dll from VB ... when I try to access it from VC++, it gives run time error as access violation.

Hi,

here is the solution:
create the dll in VB (as article describes it), function header like this:
Code:
Public Function example_function1(ByVal i As Integer) as Integer example_function = i End Function Public Function example_function2(ByRef i As Integer) as Integer example_function = i i = i * 2 End Function

in C++:
Code:
typedef int (__stdcall *ptf_test_func_1_type)(int); typedef int (__stdcall *ptf_test_func_2_type)(int*); LoadLibrary(...); //check its result... ptf_test_func_1_type p_func1=(ptf_test_func_1_type)GetProcAddress(dll_instance,"example_function1"); ptf_test_func_2_type p_func2=(ptf_test_func_2_type)GetProcAddress(dll_instance,"example_function2"); //check its results... //call function: int i =1; int ret_val = (*p_func1)(i); int ret_val2 = (*p_func2)(&i);

So simple.
Troubles begin at strings... (In VB: "As String", in c++: "BSTR")

Good luck,
Istvan
  Reply With Quote
 
     


Question Tools Search this Question
Search this Question:

Advanced Search
Display Modes

 
Similar Sponsors

Similar Questions
Question Asker Topic Answers Last Post
Accessing adoption records DonjaFox Adoption 7 Jan 19, 2007 08:13 AM
People Are Accessing My Hard Drives! helphungry Networking 10 Aug 28, 2006 11:42 PM
Accessing computer on domain ryansajid Networking 1 Feb 8, 2006 11:09 AM
Accessing FTP through My Network Places Kohoutek Internet & the Web 2 Feb 8, 2006 03:05 AM
Two Network cards in One computer accessing two networks.. Jubei Networking 2 Apr 15, 2005 07:04 AM




Copyright ©2003 - 2007, Ask Me Help Desk.
All times are GMT -8. The time now is 10:32 PM.

Content Relevant URLs by vBSEO 3.0.0 RC6 © 2006, Crawlability, Inc.