BOOL CreateLink(LPSTR szPath,LPSTR szLink)
{
CoInitialize(NULL);
HRESULT hres;
IShellLink* psl;
IPersistFile* ppf;
WORD wsz[MAX_PATH];
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
IID_IShellLink, (void**)&psl);
if(FAILED(hres))
return FALSE;
psl->SetPath(szPath);
hres = psl->QueryInterface(IID_IPersistFile, (void**)&ppf);
if(FAILED(hres))
return FALSE;
MultiByteToWideChar(CP_ACP, 0, szLink, -1, wsz, MAX_PATH);
hres = ppf->Save(wsz, STGM_READWRITE);
ppf->Release();
psl->Release();
CoUninitialize();
return TRUE;
}这个函数是用来创建快捷方式的。VC6,在非unicode工程中工作正常,但在unicode工程中报错:
error C2664: 'SetPath' : cannot convert parameter 1 from 'char *' to 'const unsigned short *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
这个如何解决啊?

解决方案 »

  1.   

    把函数定义改成CreateLink(LPTSTR szPath,LPTSTR szLink)
    程序中使用TCHAR代替char,用_T("string")的形式使用字符串常量。
      

  2.   

    看你传进来的szPath是不时Unicode的,是的话,直接定义LPWSTR szPath
      

  3.   

    用1楼的方法或者用函数MultiByteToWideChar转换
      

  4.   

    按一楼修改后MultiByteToWideChar(CP_ACP, 0, szLink, -1, wsz, MAX_PATH); 一行报错:
    error C2664: 'MultiByteToWideChar' : cannot convert parameter 3 from 'unsigned short *' to 'const char *'
            Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
      

  5.   

    既然已经是LPTSTR了,MultiByteToWideChar(CP_ACP, 0, szLink, -1, wsz, MAX_PATH); 这行可以去掉了
    下面一行
    hres = ppf->Save(szLink, STGM_READWRITE);