C++函数转化成C# 50分!

成都锦福工作室 2009-11-09 11:07:39
bool QueryDBList(DATETIME &dbDate,char *dbBuff,int &dbLen);

该函数是C++写的调用某一天数据库日志的代码 请问如何转化成C#的方法呢?
...全文
151 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
godlxldog 2009-11-09
  • 打赏
  • 举报
回复
[DllImport("DBQuery.dll")]
public static extern unsafe bool QueryDBList(ref DateTime dbDate,[MarshalAs(UnmanagedType.LPWStr)]StringBuilder dbBuff,ref int dbLen)
lzsh0622 2009-11-09
  • 打赏
  • 举报
回复
C++ datetime 对应 C#的结构
  • 打赏
  • 举报
回复
bool QueryDBList(DATETIME &dbDate,char *dbBuff,int &dbLen);

C++datetime还是对应C#的datetime吗? &dbDate变量中的&是什么意思呢?还有int &dbLen中也有这个符号
char *dbBuff对应的是string? 我搜索了一下 有些地方对应的是byte...迷惑!
lzsh0622 2009-11-09
  • 打赏
  • 举报
回复
数据类型对应好就行了


C++ C#
=====================================
WORD ushort
DWORD uint
UCHAR int/byte 大部分情况都可以使用int代替,而如果需要严格对齐的话则应该用bytebyte
UCHAR* string/IntPtr
unsigned char* [MarshalAs(UnmanagedType.LPArray)]byte[]/?(Intptr)
char* string
LPCTSTR string
LPTSTR [MarshalAs(UnmanagedType.LPTStr)] string
long int
ulong uint
Handle IntPtr
HWND IntPtr
void* IntPtr
int int
int* ref int
*int IntPtr
unsigned int uint
COLORREF uint
  • 打赏
  • 举报
回复
可能是我表达不清楚 我的意思是调用该方法

[DllImport("DBQuery.dll")]
public static extern unsafe bool QueryDBList(?,?,?)

其中应该填写什么类型呢
ztenv 2009-11-09
  • 打赏
  • 举报
回复
编译成C++dll,然后在C#中调用吧,如果你的函数太复杂这就是最好的办法;
宝_爸 2009-11-09
  • 打赏
  • 举报
回复
没啥办法吧,只能手动翻译。
或者使用C++编译好的dll,用Platform Invoke调用它

110,534

社区成员

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

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

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