怎么用C++生成动态连接库
要用C++做个DLL,程序代码是网上找的但是无法生成
代码如下:
HRESULT CShortCutDlg::CreateThumbnail(DWORD dwWidth, DWORD dwHeight, HBITMAP* pThumbnail)
{
LPITEMIDLIST pidlItems = NULL, pidlURL = NULL, pidlWorkDir = NULL;
ULONG ulParseLen = 0;
HRESULT hr;
WCHAR pszPath[MAX_PATH];
DWORD dwPriority = 0, dwFlags = IEIFLAG_ASPECT;
SIZE size = { dwWidth, dwHeight };
IExtractImage* peiURL = NULL; // nterface is used to request a thumbnail image from a Shell folder
IShellFolder* psfDesktop = NULL;
IShellFolder* psfWorkDir = NULL;
IMalloc* pMalloc = NULL;
wstring wsDir,wsFile,wsTempFile;
// 初始化Com库
if ( CoInitialize( NULL ) != 0 )
{
AfxMessageBox( _T( "初始化Com库失败!" ) );
goto OnExit;
}
// 获得 IMalloc接口
hr = SHGetMalloc( &pMalloc );
if ( FAILED( hr ) )
{
goto OnExit;
}
// 获得桌面文件夹
hr = SHGetDesktopFolder(&psfDesktop);
if(FAILED(hr)) goto OnExit;
//// create shortcut if URL
//if(PathIsURLW(m_wsPath.c_str())) {
// wsTempFile = m_wsTempPath; wsTempFile += TEMP_URL;
// // 自定义函数CreateURLShortcut
// if(!CreateURLShortcut(m_wsPath.c_str(), wsTempFile.c_str())) goto OnExit;
// wsDir = m_wsTempPath;
// wsFile = TEMP_URL;
//}
//else {
// wsDir = m_wsDir;
// wsFile = m_wsFile;
//}
wsDir = m_wsDir;
wsFile = m_wsFile;
// get working directory
wcscpy(m_wsBuffer,wsDir.c_str());
// ParseDisplayName:Translates a file object's or folder's display name into an item identifier list.
hr = psfDesktop->ParseDisplayName(NULL, NULL, m_wsBuffer, &ulParseLen, &pidlWorkDir, NULL);
if(FAILED(hr)) goto OnExit;
hr = psfDesktop->BindToObject(pidlWorkDir, NULL, IID_IShellFolder, (LPVOID*)&psfWorkDir);
if(FAILED(hr)) goto OnExit;
psfDesktop->Release();
psfDesktop = NULL;
pMalloc->Free(pidlWorkDir);
pidlWorkDir = NULL;
// retrieve link information
wcscpy(m_wsBuffer,wsFile.c_str());
hr = psfWorkDir->ParseDisplayName(NULL, NULL, m_wsBuffer, &ulParseLen, &pidlURL, NULL);
if(FAILED(hr)) goto OnExit;
// query IExtractImage
hr = psfWorkDir->GetUIObjectOf(NULL, 1, (LPCITEMIDLIST*)&pidlURL, IID_IExtractImage, NULL, (LPVOID*)&peiURL);
if(FAILED(hr)) goto OnExit;
// define thumbnail properties
hr = peiURL->GetLocation(pszPath, MAX_PATH, &dwPriority, &size, 16, &dwFlags);
if(FAILED(hr)) goto OnExit;
// generate thumbnail
hr = peiURL->Extract(pThumbnail);
if(FAILED(hr)) goto OnExit;
// clean-up IExtractImage
peiURL->Release();
peiURL = NULL;
OnExit:
// free allocated structures
if(peiURL != NULL) peiURL->Release();
if(pidlURL != NULL) pMalloc->Free(pidlURL);
if(pidlWorkDir != NULL) pMalloc->Free(pidlWorkDir);
if(psfDesktop != NULL) psfDesktop->Release();
if(psfWorkDir != NULL) psfWorkDir->Release();
CoUninitialize();
return hr;
}
说是要引入#include <windows.h> 但是引入了还是没有效果
[解决办法]
创建一个“Win32项目”,选择“DLL”。函数定义改成:
HRESULT CreateThumbnail(DWORD dwWidth, DWORD dwHeight, HBITMAP* pThumbnail);
再给项目添加一个def文件,里面加上:
LIBRARY DLL名称
EXPORTS
CreateThumbnail
[解决办法]
HRESULT 在我的编辑器里没有被识别为一个类型
[解决办法]
项一下~!
[解决办法]
该回复于2010-03-17 09:02:38被版主删除
[解决办法]
我有一个c++程序,在mfc下的。一个.c和一个.h文件,要怎么生成动态库和静态库,求帮助,谢谢