Calling a VB .NET DLL from VC++ .NET

oval

Newcomer
Joined
Mar 23, 2003
Messages
11
hello, i have created a very small DLL created in VC++ .NET that interacts with mIRC. I don't know C++. I am much more comfortable with Visual Basic. What i want to do is create a Visual Basic DLL that will be called by the C++ application. I have found much information about doing this with pre .NET vb and vc++. But could not manage to get it working in .NET... Here is a link of a step by step example I was looking at that uses older versions of vb and vc++. I would much appreciate if someone could help me do this in .NET... thankyou!

http://www.codeproject.com/dll/vbactivexwithvc.asp?df=100&forumid=1234&select=498443
 
All you have to do to add VB.NET DLL to ManagedC++ is add a reference to the project, just like you would do in VB. Right click your project and go to add reference.
 
mutant said:
All you have to do to add VB.NET DLL to ManagedC++ is add a reference to the project, just like you would do in VB. Right click your project and go to add reference.


There is no "Add Reference".
 
LOl Im sorry. Thinking of VB and C# too much :)

In your code type:
Code:
#using "dllname.dll"
It has to be in the directory with your source, or you will have to specify full path.
 
mutant said:
LOl Im sorry. Thinking of VB and C# too much :)

In your code type:
Code:
#using "dllname.dll"
It has to be in the directory with your source, or you will have to specify full path.


i'm getting a very weird error, here is the code of my managed c++ project....
=========================
#include "stdafx.h"

#using <mscorlib.dll>
#include <tchar.h>

#using "C:\temp\Mirc\vb\bin\vb.dll"
using namespace vb;

using namespace System;

// This is the entry point for this application
int _tmain(void)
{
vb::cls *t;
t->test();
return 0;
}
=========================


here's the code to my vb.dll...
=========================
Public Class cls
Public Function test()
MsgBox("VB ActiveX DLL")
End Function
End Class
=========================
 
An unhandled exception of type 'System.IO.FileNotFoundException' occurred in unknown module.
Additional information: File or assembly name vb, or one of its dependencies, was not found.
 
Its should be finding the DLL because it woudlnt let you compile. When is that error happening?
 
oh my god it works! hehe. the vb dll has to be in the debug dir where the vc executable is. thanks so much for your help!
===============================================

#include "stdafx.h"

#using <mscorlib.dll>
#include <tchar.h>

#using "Debug/vb.dll"
using namespace ::vb;

using namespace System;

// This is the entry point for this application
int _tmain(void)
{
cls *t;
t->test();
return 0;
}
 
Now to get it working in a MFC .NET application.... not as easy as the managed c++ it seems. This code always returns the creation error. This code is from my MFC DLL application.

these 2 line are in the stdafx.h right above the last line of code..
#import "Debug/vb.tlb"
using namespace vb;

=================

#define ret(x) { lstrcpy(data,x); return 3; }

extern "C" {
int WINAPI version(HWND, HWND, char *data, char*, BOOL, BOOL) {
HRESULT hresult;
CLSID clsid;
CoInitialize(NULL); //initialize COM library
hresult=CLSIDFromProgID(OLESTR("vb.cls"), &clsid); //retrieve CLSID of component
_cls *t;
hresult = CoCreateInstance(clsid,NULL,CLSCTX_INPROC_SERVER,__uuidof(_cls),(LPVOID *) &t);
if(FAILED(hresult)) {
AfxMessageBox("Creation Failed");
return 0;
}
//t->test(); //call method
CoUninitialize(); //Unintialize the COM library

ret("ovals .1");
}
}
 
I dont know the answer for that :( but i have a question.
Why would you be using MFC if .NET Framework is better and to run your dll anywhere you need the .NET framework anyway?
 
i should of said or Win32. The C++ portion that i already have working is actually a Win32 project... I have also got this working in MFC. here's the main part of the existing code that works... i need get data from mirc (which is already working)... and basically pass it to my vb.dll. but i can't seem to import it successfully. It only lets me put the import line in certain places.. the example link at the top of this thread says that you need to put it in the stdafx.h file inbetween 2 certain lines of code. but my project doesn't have those 2 lines of code etc....

Code:
// Win32

extern "C" {
	void WINAPI LoadDll(void*) {
		CoInitialize(0);
		CoCreateInstance(CLSID_ShellLink,0,CLSCTX_INPROC_SERVER,IID_IShellLink,(void**)&psl);
		psl->QueryInterface(IID_IPersistFile,(void**)&ppf);
	}

	int WINAPI UnloadDll(int timeout) {
		if (!timeout) { ppf->Release(); psl->Release(); CoUninitialize(); }
		return 0;
	}

	int WINAPI version(HWND, HWND, char *data, char*, BOOL, BOOL) {
		ret("ovals .1");
	}

	int WINAPI OnJoin(HWND, HWND, char *data, char*, BOOL, BOOL) {
		// this is where i want to call my VB dll
		// then have the vb dll send its reaction to this dll
		// then have this dll relay the reaction to mIRC
		// mIRC --> C++.DLL --> VB.DLL --> C++.DLL --> mIRC
	}
}
 
Last edited:
Back
Top