非托管的DllImport,非.NET的DLL .NET项目代表的char *虚空__stdcall [英] DllImport Unmanaged, Non .NET Dll to .NET Project Representing Char * and Void __StdCall

查看:218
本文介绍了非托管的DllImport,非.NET的DLL .NET项目代表的char *虚空__stdcall的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写在Borland的C ++,我需要导入一个DLL非.net和非托管。它返回void,并且对功能标识__stdcall。它还需要的char *的传递。当我尝试它作为引用添加到我的项目在VS 2005,它返回无效组装的误差。



如何在C#中做到这一点。



这是我目前已经和它不工作:<? / p>

 函数[DllImport(Project1.dll,CallingConvention = CallingConvention.StdCall)] 
公共静态外部的IntPtr CustomerForm
(字符串标题);


解决方案

有关非托管的DLL没有将其添加为参考。确保二进制DLL位于同一文件夹中的.NET EXE项目位于通常(项目)\bin\debug构建。



此外, 。请确保您有用于出口.def文件,当你建立与Borland C ++非托管的DLL



编辑:

 
LIBRARY PROJECT1
出口量
CustomerForm

而在你的Borland C ++源确保该函数声明为导出中的示例:

 
的#ifdef __cplusplus
__declspec(dllexport)的无效​​CustomerForm(字符* S);
的#endif



使用,这将确保该功能是导出且可连接<!/ P>

请确保您的DllImport属性的签名多达匹配你的本地C ++的Dll即

 
函数[DllImport的签名(Project1.dll,CallingConvention = CallingConvention.StdCall)]
公共静态外部无效CustomerForm(字符串标题);



希望这可以帮助,
最好的问候,
汤姆。


I have a DLL non .net and unmanaged written in Borland C++ that I need to import. It returns void and has the identifier __stdcall on the function. It also requires passing of char *. When I try to add it as a reference to my project in VS 2005, it returns an error of not valid assembly.

How can I do this in C#?

This what I currently have and it does not work:

[DllImport ("Project1.dll", CallingConvention=CallingConvention.StdCall)]
    public static extern IntPtr CustomerForm
        (String caption);

解决方案

For an unmanaged DLL you do not add it as a reference. Make sure the binary DLL is located in the same folder as the build where the .NET EXE project resides in usually {project}\bin\debug.

Also, make sure that you had a .DEF file for the exports when you built the unmanaged DLL with Borland C++.

Edit:

LIBRARY Project1
EXPORTS
    CustomerForm

And in your Borland C++ source make sure that the function is declared as export, for an example:

#ifdef __cplusplus
__declspec(dllexport) void CustomerForm(char *s);
#endif

Using this will ensure that the function is exportable and can be linked!

Make sure the signature of your DllImport attribute matches up to the signature of your native C++ Dll i.e.

[DllImport ("Project1.dll", CallingConvention=CallingConvention.StdCall)]
    public static extern void CustomerForm(string caption);

Hope this helps, Best regards, Tom.

这篇关于非托管的DllImport,非.NET的DLL .NET项目代表的char *虚空__stdcall的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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