请问 c#如何调用c++的dll? 就比如下面这个
怪我咯
怪我咯 2017-04-17 13:54:23
0
4
686
CString GetCurrentDir(void)
{
    TCHAR sDrive[_MAX_DRIVE];
    TCHAR sDir[_MAX_DIR];
    TCHAR sFilename[_MAX_FNAME];
    TCHAR Filename[_MAX_FNAME];
    TCHAR sExt[_MAX_EXT];
    
    GetModuleFileName(AfxGetInstanceHandle(),Filename,_MAX_PATH);
    _tsplitpath(Filename,sDrive,sDir,sFilename,sExt);
    CString HomeDir(CString(sDrive)+CString(sDir));    
    if (HomeDir.GetAt(HomeDir.GetLength()-1)!=_T('\\'))
        HomeDir+=_T('\\');
    return HomeDir;
}


    char path[256];
    sprintf(path, "%splaylist1.txt", GetCurrentDir());
    result = AddWindowEx(iCom, iAddress, iSchedule, 0, 0, 128, 32, path);
    if (!result)
        AfxMessageBox("设置播放数据playlist1.txt失败");

我怎么调用AddWindowEx 这个方法
主要是 sprintf(path, "%splaylist1.txt", GetCurrentDir()); 这一句是干嘛的 百度了一圈也没看到答案 有没有c++大神 帮忙看看

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(4)
黄舟

sprintf can be replaced by C#'s string.Format(). If you use C#6, you can directly write the template string $"", and GetCurrentDir should be replaced by Environment.CurrentDirectory.

var path = string.Format("{0}playlist1.txt", GetCurrentDir());
path = $"{GetCurrentDir()playlist1.txt}";

Is AddWindowEx a custom function?

左手右手慢动作

c# can only call c functions through the platform

黄舟
using System.Runtime.InteropServices;
[DLLImport("xxx.dll")]
public static extern 返回值 方法名(参数);

Then just call the method directly

黄舟

String formatting function, encyclopedia has entry

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!