有人可以帮助我将这段代码从c ++转换为c# [英] could someone help me with translating this code from c++ to c#

查看:88
本文介绍了有人可以帮助我将这段代码从c ++转换为c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助我将这段代码从c ++转换为c#



could someone help me with translating this code from c++ to c#



typedef int (__stdcall *TAQQHook)(WPARAM wParam, LPARAM lParam);
typedef TAQQHook *PAQQHook;
typedef int (__stdcall *TAQQService)(WPARAM wParam,LPARAM lParam);
typedef TAQQService *PAQQService;

#define CALLSERVICE_NOTFOUND 0x80000000
#define MAXMODULELABELLENGTH 64

typedef struct TPluginLink
{
 wchar_t* Path;
 HANDLE (__stdcall *CreateHookableEvent)(wchar_t* Name);
 int (__stdcall *DestroyHookableEvent)(HANDLE hEvent);
 int (__stdcall *NotifyEventHooks)(HANDLE hEvent, WPARAM wParam, LPARAM lParam);
 HANDLE (__stdcall *HookEvent)(wchar_t* Name, TAQQHook HookProc);
 HANDLE (__stdcall *HookEventMessage)(wchar_t* Name, HWND Handle, unsigned int Msg);
 int (__stdcall *UnhookEvent)(HANDLE hHook);
 HANDLE (__stdcall *CreateServiceFunction)(wchar_t* Name, TAQQService ServiceProc);
 void* CreateTransientServiceFunction;
 int (__stdcall *DestroyServiceFunction)(HANDLE hService);
 int (__stdcall *CallService)(wchar_t* Name, WPARAM wParam, LPARAM lParam);
 int (__stdcall *ServiceExists)(wchar_t* Name);
} TPluginLink; 
typedef
 TPluginLink *PPluginLink;

typedef struct TVersionInfo
{
 int a;
 int b;
 int c;
 int d;
 
 TVersionInfo (): a(0), b(0), c(0), d(0) { }
 TVersionInfo (int _a, int _b, int _c, int _d): a(_a), b(_b), c(_c), d(_d) { }
 
} TVersionInfo;



TVersionInfo PLUGIN_GET_VERSION(DWORD ver);

DWORD PLUGIN_MAKE_VERSION(int a, int b, int c, int d)
{
 return (((((DWORD)(a))&0xFF)<<24)|((((DWORD)(b))&0xFF)<<16)|((((DWORD)(c))&0xFF)<<8)|(((DWORD)(d))&0xFF));
}

TVersionInfo PLUGIN_GET_VERSION (DWORD ver)
{
 return TVersionInfo (
 (ver & 0xFF000000) >> 24,
 (ver & 0x00FF0000) >> 16,
 (ver & 0x0000FF00) >> 8,
 (ver & 0x000000FF));
}

int CompareVersion (DWORD vera, DWORD verb)
{
 TVersionInfo v1 = PLUGIN_GET_VERSION (vera);
 TVersionInfo v2 = PLUGIN_GET_VERSION (verb);

 if (v1.a < v2.a) return -1;
 else if (v1.a > v2.a) return 1;

 if (v1.b < v2.b) return -1;
 else if (v1.b > v2.b) return 1;

 if (v1.c < v2.c) return -1;
 else if (v1.c > v2.c) return 1;

 if (v1.d < v2.d) return -1;
 else if (v1.d > v2.d) return 1;

 return 0;
}

推荐答案

您最好的选择是将其放入C ++/CLI dll,这样您就可以直接运行C ++代码,并从托管代码中调用它.
Your best bet is to put it into a C++/CLI dll, so you can run the C++ code directly, and call it from managed code.


我知道.但是我需要用C#结尾编写的代码,因为我现在睡了两个晚上.而且我仍在尝试解决问题
I know that. But i need this code written in c# end becouse of that i dident sleep for two deys now. And im still trying to solve the problem


好吧,如果您必须用困难的方式做到这一点,那么您只需要弄清楚就可以了. www.pinvoke.net [ ^ ]可能会帮助您确定如何设置此结构,并且,如果您正在调用dll(如我所怀疑的那样,还有其他签名),则需要使用pinvoke给他们打电话.大部分操作都很简单,它不应该花那么长时间,也就是说,您不应该花2天的时间就没有任何内容可发布.坦率地说,它大部分都可以正常使用.
Well, if you must do it the hard way, then you need to just figure it out. www.pinvoke.net[^] may help you working out how to set out this struct, and if you''re calling a dll, as I suspect with those other signatures, then you''re going to need to use pinvoke to call them. Most of this is pretty easy, it shouldn''t have taken you this long, that is, you shouldn''t have spent 2 days and have nothing to post as your first efforts. Most of it will work as it stands, to be frank.


这篇关于有人可以帮助我将这段代码从c ++转换为c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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