C#调用DLL

famer 2011-04-15 04:47:42
函数声明:
char * App_report ()
输入/输出参数
输入参数: 无
输出参数: 返回用户上行状态报告的字符指针:
前16个字节为用户下行状态报告ID:
接着8个字节为用户下行状态报告状态
后面4个字节为标志(1.成功.0.失败)
返回值: 长度大于10为有下行状态报告过来,否则没状态报告


上面是一接口文档说明。
请问这个在C#中如何调用。
...全文
201 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
famer 2011-04-18
  • 打赏
  • 举报
回复
什么意思?
返回值是指针字符
lhp89 2011-04-18
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 famer 的回复:]
[DllImport("smsdll.dll", EntryPoint = "App_report", CallingConvention = CallingConvention.Cdecl)]
public static extern byte App_report ();//

listBox1.Items.Add(App_report().ToString());

上面是……
[/Quote]
famer 2011-04-18
  • 打赏
  • 举报
回复
string 要报像。尝试读取或写入受保护的内存。这通常指示其他内存已损坏。

请问怎么用这个函数呢?我是从DELPHI转过来的。很多不懂,请多多指教
isjoe 2011-04-18
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 famer 的回复:]
[DllImport("smsdll.dll", EntryPoint = "App_report", CallingConvention = CallingConvention.Cdecl)]
public static extern byte App_report ();//

listBox1.Items.Add(App_report().ToString());

上面是……
[/Quote]

为何返回值byte,byte的位都是1就是255.....
famer 2011-04-18
  • 打赏
  • 举报
回复
我改成 stdcall 返回值还是一样的。难道该函数返回值就是255吗?
famer 2011-04-18
  • 打赏
  • 举报
回复
[DllImport("smsdll.dll", EntryPoint = "App_report", CallingConvention = CallingConvention.Cdecl)]
public static extern byte App_report ();//

listBox1.Items.Add(App_report().ToString());

上面是我的代码
famer 2011-04-18
  • 打赏
  • 举报
回复
返回指是 255 我现在就不知道是否正确
Just4life 2011-04-18
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 caozhy 的回复:]
首先确定那个函数是 stdcall 的,而且已经被导出。

然后这个 string App_report() 就可以。
[/Quote]

+++
famer 2011-04-18
  • 打赏
  • 举报
回复
函数是Cdecl
请叫我卷福 2011-04-18
  • 打赏
  • 举报
回复
C#调用DLL文件时参数对应表
Wtypes.h中的非托管类型 非托管 C语言类型 托管类名 说明
HANDLE void* System.IntPtr 32 位
BYTE unsigned char System.Byte 8 位
SHORT short System.Int16 16 位
WORD unsigned short System.UInt16 16 位
INT int System.Int32 32 位
UINT unsigned int System.UInt32 32 位
LONG long System.Int32 32 位
BOOL long System.Int32 32 位
DWORD unsigned long System.UInt32 32 位
ULONG unsigned long System.UInt32 32 位
CHAR char System.Char 用 ANSI 修饰。
LPSTR char* System.String 或 System.StringBuilder 用 ANSI 修饰。
LPCSTR Const char* System.String 或System.StringBuilder 用 ANSI 修饰。
LPWSTR wchar_t* System.String 或System.StringBuilder 用 Unicode 修饰。
LPCWSTR Const wchar_t* System.String 或System.StringBuilder 用 Unicode 修饰。
FLOAT Float System.Single 32 位
DOUBLE Double System.Double 64 位
dreamrising 2011-04-18
  • 打赏
  • 举报
回复
用stringbuilder要手动分配内存
famer 2011-04-18
  • 打赏
  • 举报
回复
StringBuilder 试了。用这个出现以下错误 尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
头都要弄大了
isjoe 2011-04-18
  • 打赏
  • 举报
回复
将返回值改为StringBuilder,试试看
threenewbee 2011-04-15
  • 打赏
  • 举报
回复
首先确定那个函数是 stdcall 的,而且已经被导出。

然后这个 string App_report() 就可以。
小路子的宝 2011-04-15
  • 打赏
  • 举报
回复
能不用汉字不?

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧