C#Interop:c ++访问冲突很长 [英] C# Interop: Access violation with c++ long

查看:63
本文介绍了C#Interop:c ++访问冲突很长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好


我正在尝试将数据发送到外部DLL。 我有几个入口点,但我被困在一个。  DLL的文档显示以下内容:


int __stdcall __declspec(dllexport)StartHW(long freq)


因此,我将dll导入定义为遵循


        [DllImport(" externalDLL.dll",CallingConvention = CallingConvention.StdCall)]¥b $ b       公众  static extern int StartHW(int freq);



调用约定是正确的。 现在我明白C ++很长(如文档中所示)是C#中的Int32,这就是我放置int的原因。



现在C#程序中的代码执行以下操作:


               结果;

                result = StartHW(7000000);


我得到一个未处理的异常:系统访问违规。


有没有人有任何想法我做错了什么?


谢谢,汤姆




解决方案

您应该明确客户端和服务器的位数。



Hi

I am attempting to send data to an external DLL.  I have several entry points working but I am stuck on one.  The documentation for the DLL shows the following:

int __stdcall __declspec(dllexport) StartHW(long freq)

So, I define a dll import as follows

        [DllImport("externalDLL.dll", CallingConvention = CallingConvention.StdCall)]
        public  static extern int StartHW(int freq);

The calling convention is correct.  Now I understand that a C++ long (as in the documentation) is an Int32 in C# so that is why I put an int.

Now the code in the C# program does the following:

                int result;
                result = StartHW(7000000);

and I get a unhandled exception: system access violation.

Does anyone have any ideas what I am doing wrong?

Thanks, Tom

解决方案

You should make clear what's the bitness of client and server.


这篇关于C#Interop:c ++访问冲突很长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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