如何从本机dll接收字符串? [英] How to receive a string from a native dll?

查看:104
本文介绍了如何从本机dll接收字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

请告诉我如何从本地dll(用EVC ++编写)将字符串接收到紧凑的C#项目中.

请举例说明.

提前致谢.
bikram singh

Hello everybody

Please tell me of how can i receive a string from a native dll (written in EVC++) into a compact C# project.

Please explain with example.

Thanks in advance.
bikram singh

推荐答案

假设您要调用user32.dll函数GetWindowText
以下是示例C#代码
Suppose you are going to call user32.dll function GetWindowText
following is the sample C# code
//C++ function syntax ->     int GetWindowText( HWND hWnd, LPTSTR lpString, int nMaxCount );
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);

//Form's button click event.
private void button1_Click(object sender, EventArgs e)
{
    const int nMaxCount = 255;
    StringBuilder str = new StringBuilder(nMaxCount);
    GetWindowText(this.Handle, str, nMaxCount);
}


[ ^ ]文章应该可以帮助您入门.
This[^] article should get you started.


这篇关于如何从本机dll接收字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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