C#中DllImport用法和路径问题

C#中DllImport用法和路径问题


2024年1月11日发(作者:)

DLL 需传出char *类型

[DllImport(“")]

// 传出值public static extern int mySum (StringBuilder abuf, StringBuilder bbuf );

//DLL中申明

extern “C” __declspec(dllexport) int WINAPI mySum(char * astr,char * bstr)

{

//传出char * 改变astr bstr -->abuf, bbuf可以被改变 return a+b;

}

DLL 回调函数

BOOL EnumWindows(WNDENUMPROC lpEnumFunc, LPARAM lParam)

using System;

using pServices;

public delegate bool CallBack(int hwnd, int lParam); //定义委托函数类型

public class EnumReportApp

{

[DllImport("user32")]

public static extern int EnumWindows(CallBack x, int y);

public static void Main() {

CallBack myCallBack = new CallBack(); EnumWindows(myCallBack, 0);

}

public static bool Report(int hwnd, int lParam)

{

("Window handle is ");

ine(hwnd); return true;

}

}

DLL 传递结构

BOOL PtInRect(const RECT *lprc, POINT pt);

using pServices;

[StructLayout(tial)]

public struct Point { public int x;

public int y; }

[StructLayout(it)]

public struct Rect

{

[FieldOffset(0)] public int left;

[FieldOffset(4)] public int top;[FieldOffset(8)] public int right;

[FieldOffset(12)] public int bottom; }

Class XXXX {

[DllImport("")]

public static extern bool PtInRect(ref Rect r, Point p);

}


发布者:admin,转转请注明出处:http://www.yc00.com/news/1704987491a1385793.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信