|
-
July 23rd, 2009, 11:56 AM
#1
Calling Visual Basic 2008 functions from VC++2008
Hi,
I am new to mixed language programming and need to call a VB 2008 function (for which I have the source code) from a C++ code. I have Visual Studio 2008 with VB and VC++.
I searched through the web for several days now and getting extremely confused and frustrated because all methods seem to either imply that using VB6 would be simpler (eg, http://support.microsoft.com/kb/194873 which I am unable to follow in VS2008 because there are no activeX dlls..), or give incomplete solutions that I am unable to get compiled (eg, http://msdn.microsoft.com/en-us/libr...zx(VS.71).aspx).
Please, could somebody post a working example on how to call a simple VB code (below) from a simple C main unit (also below) using Visual Studio 2008?
I just want the simplest example that works and will build up from there - at the moment just getting nowhere after several days of trying solutions from the web :-( I have previously worked with COM objects etc, but just cant get my head around the C++/VB coupling and dont know the syntax for it..
Many thanks in advance!
--------------
' VB code to be called
Option Explicit On
Public Class Class1
Public Function vbfunk(ByVal x As Integer) As Integer
MsgBox(x)
vbfunk= x
End Function
End Class
----------------------------
// C code to call VB
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#import "vbdll.tlb" no_namespace
int main()
{
int rst;
// I understand I need a COM-type DLL??
//CoInitialize(NULL);
// some connection to add here
rst=vbfunk(1);
//CoUninitialize();
return 1;
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|