DllImportAttribute CallingConvention [英] DllImportAttribute CallingConvention

查看:94
本文介绍了DllImportAttribute CallingConvention的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Class包装器中调用了一个非托管DLL,如下所示。


命名空间blah

{

[DllImport( " DLLName.DLL",EntryPoint =" BlahEntryPoint",

CallingConvention = CallingConvention.ThisCall]

public static extern void blahFn(out long blah,out long blah2) ;


类密封ClassBlah

{

私人ClassBlah()

{

}


}

}


为什么我要通过ThisCall的CallingConvention来调用它,它只是

正常的C函数在DLL中。为什么StdCall不工作?


其他调用约定会发生的是out参数是

没有设置,但是使用ThisCall,它们设置正常,或者看起来是。我发现它很奇怪。


谢谢

解决方案

Tickle先生,


原始函数的声明是什么?如果需要

指针,然后你应该使用ref参数,而不是出来。

此外,该函数是否采用64位整数? C中的长整数是32位


如果你是的话,STDCALL机制应该可以工作使用它。


希望这会有所帮助。

-

- Nicholas Paldino [.NET / C#MVP]
- ni ************** @ exisconsulting.com


" Mr.Tickle" <先生****** @ mrmen.com>在消息中写道

新闻:Oo ************** @ TK2MSFTNGP09.phx.gbl ...

我打电话给不受管理DLL在类包装器中如下所示。

命名空间blah
{DllImport(" DLLName.DLL",EntryPoint =" BlahEntryPoint",
CallingConvention = CallingConvention.ThisCall]
public static extern void blahFn(out long blah,out long blah2);

class sealed ClassBlah
{
私人ClassBlah()
{
}

}


为什么我要使用ThisCall的CallingConvention来调用它,它只是正常的  C函数在DLL中。为什么StdCall不会工作?

其他调用约定会发生out参数未设置,但使用ThisCall,它们设置正常或出现我发现它是
奇数。

谢谢



Nop,我试过ref和它没有帮助,这是我能得到的唯一方法它返回

值与thiscall一起。


Nicholas Paldino [.NET / C#MVP]" < NI ************** @ exisconsulting.com>在消息新闻中写了

:#p ************** @ TK2MSFTNGP11.phx.gbl ...

Tickle先生,

原始功能的声明是什么?如果它需要一个
指针,那么你应该使用ref指针。参数,而不是出来。
此外,该函数是否采用64位整数? C中的长整数是32位整数,其中在.NET中它是64位整数。

STDCALL机制应该可以正常使用。
<希望这会有所帮助。

-
- Nicholas Paldino [.NET / C#MVP]
- ni ************** @ exisconsulting.com

Mr.Tickle ; <先生****** @ mrmen.com>在消息中写道
新闻:Oo ************** @ TK2MSFTNGP09.phx.gbl ...

我正在调用一个非托管DLL,如下所示一个类包装器。

命名空间blah
{DllImport(" DLLName.DLL",EntryPoint =" BlahEntryPoint",
CallingConvention = CallingConvention.ThisCall]
public static extern void blahFn(out long blah,out long blah2);

类密封ClassBlah
{
私人ClassBlah()
{
}

}

我为什么要用ThisCall的CallingConvention来调用它,它的
只是正常的C函数一个DLL。为什么StdCall不会工作?

其他调用约定会发生out参数
未设置,但是使用ThisCall,它们设置为ok或看起来是.I找到它


奇数。



谢谢




因此我应该使用Int32作为参数而不是长?

Nicholas Paldino [.NET / C#MVP]" < NI ************** @ exisconsulting.com>在消息新闻中写了

:#p ************** @ TK2MSFTNGP11.phx.gbl ...

Tickle先生,

原始功能的声明是什么?如果它需要一个
指针,那么你应该使用ref指针。参数,而不是出来。
此外,该函数是否采用64位整数? C中的长整数是32位整数,其中在.NET中它是64位整数。

STDCALL机制应该可以正常使用。
<希望这会有所帮助。

-
- Nicholas Paldino [.NET / C#MVP]
- ni ************** @ exisconsulting.com

Mr.Tickle ; <先生****** @ mrmen.com>在消息中写道
新闻:Oo ************** @ TK2MSFTNGP09.phx.gbl ...

我正在调用一个非托管DLL,如下所示一个类包装器。

命名空间blah
{DllImport(" DLLName.DLL",EntryPoint =" BlahEntryPoint",
CallingConvention = CallingConvention.ThisCall]
public static extern void blahFn(out long blah,out long blah2);

类密封ClassBlah
{
私人ClassBlah()
{
}

}

我为什么要用ThisCall的CallingConvention来调用它,它的
只是正常的C函数一个DLL。为什么StdCall不会工作?

其他调用约定会发生out参数
未设置,但是使用ThisCall,它们设置为ok或看起来是.I找到它


奇数。



谢谢




I am calling an unmanaged DLL like follows in a Class wrapper.

namespace blah
{
[DllImport("DLLName.DLL", EntryPoint="BlahEntryPoint",
CallingConvention=CallingConvention.ThisCall]
public static extern void blahFn(out long blah, out long blah2);

class sealed ClassBlah
{
private ClassBlah()
{
}

}
}

Why have I to call this with the CallingConvention of ThisCall, its just
normal "C" functions in a DLL. Why wont StdCall work?

What happens with other calling conventions is that the out parameters are
NOT set, yet with ThisCall, they are set ok, or appear to be. I find it odd.

Thanks

解决方案

Mr. Tickle,

What is the declaration of the original function? If it takes a
pointer, then you should be using "ref" for the parameters, and not out.
Also, does the function take a 64-bit integer? Long in C is a 32-bit
integer, where in .NET it is a 64-bit integer.

The STDCALL mechanism should work if you are using it.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Mr.Tickle" <Mr******@mrmen.com> wrote in message
news:Oo**************@TK2MSFTNGP09.phx.gbl...

I am calling an unmanaged DLL like follows in a Class wrapper.

namespace blah
{
[DllImport("DLLName.DLL", EntryPoint="BlahEntryPoint",
CallingConvention=CallingConvention.ThisCall]
public static extern void blahFn(out long blah, out long blah2);

class sealed ClassBlah
{
private ClassBlah()
{
}

}
}

Why have I to call this with the CallingConvention of ThisCall, its just
normal "C" functions in a DLL. Why wont StdCall work?

What happens with other calling conventions is that the out parameters are
NOT set, yet with ThisCall, they are set ok, or appear to be. I find it odd.
Thanks



Nop, I tried ref and it doesnt help, the only way i can get it to return
values is with thiscall.

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:#p**************@TK2MSFTNGP11.phx.gbl...

Mr. Tickle,

What is the declaration of the original function? If it takes a
pointer, then you should be using "ref" for the parameters, and not out.
Also, does the function take a 64-bit integer? Long in C is a 32-bit
integer, where in .NET it is a 64-bit integer.

The STDCALL mechanism should work if you are using it.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Mr.Tickle" <Mr******@mrmen.com> wrote in message
news:Oo**************@TK2MSFTNGP09.phx.gbl...

I am calling an unmanaged DLL like follows in a Class wrapper.

namespace blah
{
[DllImport("DLLName.DLL", EntryPoint="BlahEntryPoint",
CallingConvention=CallingConvention.ThisCall]
public static extern void blahFn(out long blah, out long blah2);

class sealed ClassBlah
{
private ClassBlah()
{
}

}
}

Why have I to call this with the CallingConvention of ThisCall, its just normal "C" functions in a DLL. Why wont StdCall work?

What happens with other calling conventions is that the out parameters are NOT set, yet with ThisCall, they are set ok, or appear to be. I find it


odd.


Thanks




So i should use Int32 for the parameters instead of long?
"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:#p**************@TK2MSFTNGP11.phx.gbl...

Mr. Tickle,

What is the declaration of the original function? If it takes a
pointer, then you should be using "ref" for the parameters, and not out.
Also, does the function take a 64-bit integer? Long in C is a 32-bit
integer, where in .NET it is a 64-bit integer.

The STDCALL mechanism should work if you are using it.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Mr.Tickle" <Mr******@mrmen.com> wrote in message
news:Oo**************@TK2MSFTNGP09.phx.gbl...

I am calling an unmanaged DLL like follows in a Class wrapper.

namespace blah
{
[DllImport("DLLName.DLL", EntryPoint="BlahEntryPoint",
CallingConvention=CallingConvention.ThisCall]
public static extern void blahFn(out long blah, out long blah2);

class sealed ClassBlah
{
private ClassBlah()
{
}

}
}

Why have I to call this with the CallingConvention of ThisCall, its just normal "C" functions in a DLL. Why wont StdCall work?

What happens with other calling conventions is that the out parameters are NOT set, yet with ThisCall, they are set ok, or appear to be. I find it


odd.


Thanks




这篇关于DllImportAttribute CallingConvention的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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