Access VB DLL from C++ ?

This is a discussion on Access VB DLL from C++ ? within the Windows Programming forums, part of the Platform Specific Boards category; Hi! I'm have written a Visual Basic DLL, and I want to access it from my C++ code. I've read ...

  1. #1
    torbjoen
    Guest

    Access VB DLL from C++ ?

    Hi!

    I'm have written a Visual Basic DLL, and I want to access it from my C++ code.

    I've read this:
    http://www.flipcode.com/articles/article_vbdlls.shtml

    and this:
    http://www.flipcode.com/tutorials/tut_dll01.shtml

    I am able to load the DLL, but I am not able to load any functions.

    Think you can help? -Look below if you need to see my code.

    Torbjørn

    /********************************************/

    Here is my Visual Basic code:
    Code:
    ' Initializes the Class
    Private Sub Class_Initialize()
        MsgBox "This procedure is called when the DLL is loaded into memory.", vbOKOnly, "Initializing Class..."
    End Sub
    Sub Class_TestFunc()
        MsgBox "We are testing to use DLLs created in Visual Basic to work with C++", vbOKOnly, "Test function..."
    End Sub
    ' Terminates the Class
    Private Sub Class_Terminate()
        MsgBox "This procedure is called when the DLL is removed from memory.", vbOKOnly, "Cleaning up..."
    End Sub
    And this is my C++ code:

    header-file:
    Code:
    #ifndef OPCCPLUSPLUSTEST_H
    #define OPCCPLUSPLUSTEST_H
    
    #include <windows.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include "stdafx.h"
    
    typedef void (WINAPI*vbfunc)();
    
    #endif //OPCCPLUSPLUSTEST_H

    source-file:
    Code:
    // OPCCplusplusTest.cpp : Defines the entry point for the console application.
    //
    
    #include <windows.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <iostream.h>
    #include "stdafx.h"
    #include "OPCCplusplusTest.h"
    
    vbfunc TestFunc;
    
    int main(int argc, char* argv[])
    {
    	
    	HINSTANCE hLib = LoadLibrary("OPCclient.dll");
    	if(hLib == NULL)
    	{
    		printf("ERROR: Unable to load library!\n");
    		getchar();
    		return 0;
    	}
    	
    	TestFunc = (vbfunc)GetProcAddress((HMODULE)hLib,"Class_TestFunc");
    
    	if(TestFunc==NULL) {
                printf("Unable to load function(s).\n");
                FreeLibrary((HMODULE)hLib);
                return 0;
        }
    
    
    	TestFunc();
    
    	printf("Hello World!\n");
    
    	FreeLibrary((HMODULE)hLib);
    
    	return 0;
    }

  2. #2
    btq
    btq is offline
    julie lexx... btq's Avatar
    Join Date
    Jun 2002
    Posts
    161
    I know absoulutley nothin about VB but so I really can't see if this is done, but: do you export any functions from the dll?

    /btq
    ...viewlexx - julie lexx

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    11
    Hmm...I'm not really sure... I just followed the tutorial at http://www.flipcode.com/articles/article_vbdlls.shtml

    But when I compile the VB dll, there is a .exp-file generated.


    Torbjørn

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    11
    By the way: I have changed the "vbfunc" to "cfunc".

    -Kind of found out that the "c" in "cfunc" represents a char, and not the programming language c... Am I right?

    But also after doing that, it won't work..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Calling a DLL
    By jamez05 in forum C++ Programming
    Replies: 1
    Last Post: 01-05-2006, 10:13 AM
  2. dll access help
    By maverick.guru in forum C++ Programming
    Replies: 3
    Last Post: 05-31-2004, 12:36 PM
  3. Using class with DLL
    By greg2 in forum C++ Programming
    Replies: 2
    Last Post: 09-12-2003, 05:24 AM
  4. calling exe from in a Dll? Help the poor VB guy!
    By nmessick in forum C++ Programming
    Replies: 5
    Last Post: 09-16-2002, 02:01 PM
  5. DLL & free() Heap Access Violation
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 08-13-2002, 10:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21