Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am trying to call managed C++ code from COM component and at the same time trying to call that COM component from VB.Net.

Tried so many examples but none of them working.

Can anybody help me with some pointers.

*****Managed C++ code Start************
C#
namespace PrjManagedCpp {

	public ref class Class1
	{
		static void Display();
		
	};
}


*****Managed C++ code End************


Thanks in Advance,
Sanjeev

What I have tried:

1. Created Managed C++ Code :
namespace PrjManagedCpp {

public ref class Class1
{
static void Display();

};

2. Created tlb file for Managed C++ code.
3. Wrote partial COM component using tlb file.
#include "stdafx.h"
#include "CallCpp.h"
#import "D:\C++ Projects\PrjManagedCpp\Debug\PrjManagedCpp.tlb"


STDMETHODIMP CCallCpp::CallDisplayMethod(void)
{
HRESULT hRes = S_OK;
CoInitialize(NULL);

//Wanted to write some code here so that it will call method from managed C++

CoUninitialize();
return S_OK;
}

4. Created a button on VB.Net, and on this button click I would like to call COM's method which internally will call managed code's method
Posted
Updated 9-Aug-16 5:43am

1 solution

Take a look at this fine article series and this Q&A answers which I easily found with Google and am convinced that there are fine.

I have another important tip:

C++
CoInitialize(NULL);//the call takes really CPU-time


because some dlls are loaded and some code is running. Do it in the constructor of the object or in an extra init function to avoid headaches and crashes. ;-)
 
Share this answer
 
Comments
catchy87 10-Aug-16 8:20am    
Hi KarstenK,

Thanks for the help and suggestion.

Your suggestion helped me to move forward, but in above example there is no COM component in between VB.Net and Managed C++.

Without COM component, above example will do but I am looking for solution which will involve COM in between VB.Net and Managed C++.

Thanks in Advance,
Sanjeev

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900