Ask Experts Questions for FREE Help !
    john_christopher_s's Avatar
    john_christopher_s Posts: 6, Reputation: 1
    New Member

    Jan 25, 2006, 06:19 AM
    Accessing VB dll from VC++
    I have developed windows dll from VB. (The site 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

    Ademan's Avatar
    Ademan Posts: 40, Reputation: 11
    Junior Member

    Jan 28, 2006, 11:10 PM
    Well, I figure there's got to 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 you're 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 don't 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

    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
    john_christopher_s's Avatar
    john_christopher_s Posts: 6, Reputation: 1
    New Member

    Jan 29, 2006, 09:20 PM
    Thanks for your kind reply. Actually I have an executable, which is created in VC++. (I don't 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 they 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.

    Ademan's Avatar
    Ademan Posts: 40, Reputation: 11
    Junior Member

    Jan 29, 2006, 09:54 PM
    Hrm, well if load library doesn't 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 don't 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 that's 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. Anyway here are a few links that might help

    Hope that helps
    john_christopher_s's Avatar
    john_christopher_s Posts: 6, Reputation: 1
    New Member

    Jan 31, 2006, 01:36 AM
    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 didn't 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,
    Ademan's Avatar
    Ademan Posts: 40, Reputation: 11
    Junior Member

    Jan 31, 2006, 10:20 AM
    Yeah it sounds to me like the VBdll has an additional dependency, 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 dependency.

    esteve's Avatar
    esteve Posts: 1, Reputation: 1
    New Member

    Feb 10, 2006, 03:39 AM
    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.

    Here is the solution:
    Create the dll in VB (as article describes it), function header like this:
    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++:
    typedef int (__stdcall *ptf_test_func_1_type)(int);
    typedef int (__stdcall *ptf_test_func_2_type)(int*);
    //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,

Not your question? Ask your question View similar questions


Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.

Check out some similar questions!

Accessing adoption records [ 6 Answers ]

Hello! I'm wondering if anyone can help me! * I'm adopted and have recently decided to search for my biological family. Thing is there is a lot of stuff about the adoption I don't know. I've heard I am entitled to view my records, but I have no idea how to go about it. If anyone can offer me any...

People Are Accessing My Hard Drives! [ 10 Answers ]

Hello There! We have a LAN Network & there are 50 computers in that LAN connected through some routers. One of the users is accessing my hard drives & stealing data. I don't know how to prevent him & how he's doing that? I have Windows-XP (SP2) firewall is enable. There is no possibility that...

Accessing computer on domain [ 1 Answers ]

I cannot access one of my domain member. The error message is " Network Path Was Not Found".

Accessing FTP through My Network Places [ 2 Answers ]

I'm trying to access a music file I've hidden on my website, but of course I can't remember what I've called it so I thought I'd access the FTP window and look for it that way, but I'm having trouble getting on it by putting in the bit - it keeps timing out before the login box...

Two Network cards in One computer accessing two networks.. [ 2 Answers ]

I was wondering if you could help me with a small problem. I have one network card (A) accessing the internal network i.e.. Net. Printer, shared folders on other computers, and shared servers. Another network card (B) accessing a public network address for VoIP and T1 traffic i.e.. Ports...

View more questions Search