设为首页 加入收藏

TOP

在本机代码中通过 COM 使用 F#(二)
2015-07-24 05:53:33 来源: 作者: 【 】 浏览:12
Tags:代码 通过 COM 使用
ry.tlb"named_guids raw_interfaces_only

// the applications main entry point

int _tmain(int argc, _TCHAR* argv[])

{

// initialize the COM runtime

CoInitialize(NULL);

// a pointer to our COM class

comlibrary::IMathPtr pDotNetCOMPtr;

// create a new instance of the Math class

HRESULT hRes =pDotNetCOMPtr.CreateInstance(comlibrary::CLSID_Math);

// check it was created okay

if (hRes == S_OK)

{

// define a local to hold the result

long res = 0L;

// call the Add function

hRes =pDotNetCOMPtr->Add(1, 2, &res);

// check Add was called okay

if (hRes == S_OK)

{

// print the result

printf("The result was: %ld", res);

}

// release the pointer to the math COM class

pDotNetCOMPtr.Release();

}

// uninitialise the COM runtime

CoUninitialize();

}

示例的运行结果如下:

The result was: 3

当我们运行最后的程序时,必须保证ComLibrary.dll 与程序在同样的目录中,否则,COM 运行时会找不到文件。如果打算让这个库被多个客户端使用,那么,我强烈建议对程序集签名,并放在全局程序集缓存(Global Assembly Cache,GAC)中,这样,所有的客户端都能找到它,就不必要在第一个目录下都复制一份。

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇LeetCode:Length of Last Word 下一篇ecos stm32 步步深入8 - 手工打造..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: