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;
}