分类: C/C++
2008-08-01 16:58:51
GetProcAddress(hLib, "RunFileDlg")就可以得到这个函数的地址吧!可是跟踪后发现,得到结果总是NULL,后来用W32dsm看了一下发现shell32.dll中没有这个函数,觉得很是奇怪了。后来发现对于系统中没有公开的函数不能直接找到地址,而应该这样调用:
GetProcAddress(hLib, (char *)"61"); //61 是 RunFileDlg 在 Shell32.dll 中导出位置,这样的话就可以得到函数的地址了!代码的实现很简单,代码如下:
//////////////////////////////////////////////// // CString pszDllName="shell32.dll"; HINSTANCE hLib = ::LoadLibrary(pszDllName); char p[256]; HICON ico; //这儿我感觉参数应该是LPCWSTR, 但是网上说得是LPCTSTR typedef void (__stdcall *pRunFileDlg)(HWND,HICON, LPCTSTR, LPCTSTR, LPCTSTR, UINT); pRunFileDlg RunFileDlg; if (hLib==NULL) { return ; } RunFileDlg = (pRunFileDlg)GetProcAddress(hLib, (char *)61); CString name ="wolfbaby的运行"; CString sss = "输入程序路径"; LPWSTR wname=new WCHAR[100]; LPWSTR wsss=new WCHAR[100]; memset(wname,0,sizeof(WCHAR)*100); memset(wsss,0,sizeof(WCHAR)*100); MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, // character-type options name, // address of string to map name.GetLength(), // number of bytes in string wname, // address of wide-character buffer 100 ); //必须先转换到宽字符,否则后面调用的时候,结果会不对! MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, // character-type options sss, // address of string to map sss.GetLength(), // number of bytes in string wsss, // address of wide-character buffer 100 ); if(RunFileDlg!=NULL) { RunFileDlg(this->GetSafeHwnd(), NULL, NULL, (LPCTSTR)wname, (LPCTSTR)wsss,0x02); } ::FreeLibrary(hLib);下载本文示例代码