尝试通过COM从VB .NET调用托管C ++代码(VB.NET - > COM - >托管C ++)) [英] Trying to call managed C++ code from VB .NET via COM(VB.NET --> COM --> managed C++))

查看:83
本文介绍了尝试通过COM从VB .NET调用托管C ++代码(VB.NET - > COM - >托管C ++))的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我试图从COM组件调用托管C ++代码,同时尝试从VB.Net调用该COM组件。 br />


尝试了很多例子,但没有一个工作。



有人可以帮我指点一些。



*****托管C ++代码启动************

 命名空间 PrjManagedCpp {

public ref class Class1
{
static void Display();

};
}





*****托管C ++代码结束************ < br $>




先谢谢,

Sanjeev



我尝试过:



1.创建托管C ++代码:

命名空间PrjManagedCpp {



公共参考等级Class1

{

static void显示();

< br $>
};



2.为托管C ++代码创建tlb文件。

3.使用部分COM组件编写tlb文件。

#includestdafx.h

#includeCallCpp.h

#importD:\ C ++ Projects \ PrjManagedCpp \Debug \PrjManagedCpp.tlb





STDMETHODIMP CCallCpp :: CallDisplayMethod(void)

{

HRESULT hRes = S_OK;

CoInitialize(NULL);



//想写这里有一些代码,所以它将从托管C ++调用方法



CoUninitialize();

返回S_OK;

}



4在VB.Net上创建了一个按钮,在这个按钮上单击我想调用COM的方法,在内部将调用托管代码的方法

解决方案

看看这个精美文章系列和这个我很容易找到的 Q& A答案谷歌并且我确信没有问题。



我有另一个重要的提示:



 CoInitialize(NULL);  //  调用需要真正的CPU时间 





因为一些dll已加载且某些代码正在运行。在对象的构造函数或额外的init函数中执行它以避免头痛和崩溃。 ; - )


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************

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

解决方案

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:

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. ;-)


这篇关于尝试通过COM从VB .NET调用托管C ++代码(VB.NET - &gt; COM - &gt;托管C ++))的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆