描述:
在执行.ocx文件时,怎样得到.ocx文件自身的路径?
解决方案1:
我解决了
用ocx里app中的m_pszHelpFilePath
里面就有你要的路径了
OCX中
BOOL CXXXXApp::InitInstance()
{
BOOL bInit = COleControlModule::InitInstance();
if (bInit)
{
// TODO: Add your own module initialization code here.
}
//得到ocx的路径,自己处理一个这个字符串就可以了
MessageBox(NULL,this->m_pszHelpFilePath,"",0);
return bInit;
}
CString ls_FileName;
LPTSTR lpBuffer;
UINT uSize;
HANDLE hHeap;
uSize=(GetCurrentDirectory(0,NULL))*sizeof(TCHAR);
hHeap=GetProcessHeap();
lpBuffer=(LPSTR)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,uSize);
GetCurrentDirectory(uSize,lpBuffer);
ls_FileName=CString(lpBuffer);
return ls_FileName;
ls_FileName就是你的运行程式的路径了,你命真好我以测试过了正好我也要用,也花了我一点时间呢
GetModuleFileName
解决方案4: TCHAR szFilename[256] = _T("");
GetModuleFileName(_Module.GetModuleInstance(),szFilename,256);