如何从C#访问一类非托管DLL中的方法 [英] how do I access a method inside a class of unmanaged DLL from C#
问题描述
我需要在用C ++编写的非托管dll中调用类的方法。
例如,DLL名称:cast.dll
cast.dll中的类:解析器
解析器类中的一个函数:castToObject(someVal as string)
例如这里是如何在VB中动态访问它。
dim objCast
设置objCast = Server.CreateObject(cast.parser)
strCastedItem = objCast .castToObject(someValue)
我想从C#访问castToObject方法。
非常感谢您的帮助。
I need to invoke a method of a class in unmanaged dll written in C++.
e.g., DLL name: cast.dll
A class in cast.dll: parser
A function in parser class: castToObject(someVal as string)
For example here is how to access it in VB dynamically.
dim objCast
Set objCast = Server.CreateObject("cast.parser")
strCastedItem = objCast.castToObject("someValue")
I would like to access the castToObject method from C#.
Your help is highly appreciated.
推荐答案
如果你用Google搜索了....无论如何,我已经用Google搜索并找到了以下网址。可能会帮助你
将COM DLL API调用到我的c#代码中的步骤 [ ^ ]
COM Interop第1部分:C夏普客户端教程 [ ^ ]
If you have had googled.... Anyway i have googled for you and found below urls. Might help u
steps on calling COM dll API into my c# code[^]
COM Interop Part 1: C Sharp Client Tutorial[^]
Syed,
感谢您的回复。实际上,我做了研究,大多数搜索结果都指向使用DLLImport,如果DLL有一个可以调用的方法,它可以很好地工作。他们都没有展示如何调用该dll类中的方法。
然而,我确实看了你提供的链接,正如我所说的第一个谈到使用DLLImport方法对我来说不起作用,因为该函数在co-clsss中。
只有当我知道cast.dll中解析器类的GUID时,另一个链接才有用。由于我不知道GUID,并且因为com定义没有typlib,所以我无法使用解决方案来解决我的问题。
Syed,
Thanks for the response. Actually, I did research and most of the search results point on using DLLImport which works perfectly if the DLL has a method to be invoked. None of them show how to invoke methods inside a class of that dll.
However, I did look at the links you've provided and as I said the first one that talks about using the DLLImport method didn't work for me because the function is in the co-clsss.
The other link could've been useful only if I know the GUID for the "parser" class inside the cast.dll. Since I don't know the GUID and also since there is no typlib for the com definition, I couldn't use the solution to solve my problem.
这篇关于如何从C#访问一类非托管DLL中的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!