下面是在网上找的代码,可是不知为什么报这样的错误?
Mywork.obj : error LNK2019: unresolved external symbol __imp__OleLoadPicture referenced in function "long __cdecl ShowPic(char *,struct HWND__ *,int,int)" (?ShowPic@@YAJPADPAUHWND__@@HH@Z)
Mywork.obj : error LNK2001: unresolved external symbol _IID_IPicture
Mywork.obj : error LNK2019: unresolved external symbol __imp__CreateStreamOnHGlobal referenced in function "long __cdecl ShowPic(char *,struct HWND__ *,int,int)" (?ShowPic@@YAJPADPAUHWND__@@HH@Z)
emulatorDbg/Mywork.exe : fatal error LNK1120: 3 unresolved externals
请各位大侠指点一下小弟该怎么办啊?在VC6.0++下可以编译通过,可在EVC4.0下面就编译不过了,出现了上面的问题.
// lpstrFile:文件名(最好是包含路径在内)
// hWnd
// nScrWidth:输出图片的宽度
// nScrHeight:输出图片的高度
// nScrWidth、nScrHeight是输出图片的实际大小,换而言之是指缩放后的尺寸
HRESULT ShowPic(char *lpstrFile,HWND hWnd,int nScrWidth,int nScrHeight)
{
HDC hDC_Temp=GetDC(hWnd);
IPicture *pPic;
IStream *pStm;
// AfxOleInit();
BOOL bResult;
HANDLE hFile=NULL;
// DWORD dwFileSize,dwByteRead;
LONG dwFileSize;
DWORD dwByteRead;
//打开硬盘中的图形文件
hFile=CreateFile(_T("lpstrFile"),GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if(hFile!=NULL)//INVALID_HANDLE_value)
{
dwFileSize=GetFileSize(hFile,NULL);//获取文件字节数
if(dwFileSize==0xFFFFFFFF)
return E_FAIL;
}
else return E_FAIL;
//分配全局存储空间
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
LPVOID pvData = NULL;
if(hGlobal == NULL)
return E_FAIL;
if((pvData = GlobalLock(hGlobal)) == NULL)//锁定分配内存块
return E_FAIL;
ReadFile(hFile,pvData,dwFileSize,&dwByteRead,NULL);//把文件读入内存缓冲区
GlobalUnlock(hGlobal);
CreateStreamOnHGlobal(hGlobal, TRUE, &pStm);
//装入图形文件
bResult=OleLoadPicture(pStm,dwFileSize,TRUE,IID_IPicture,(LPVOID*)&pPic);
// (LPSTREAM lpstream, LONG lSize, BOOL fRunmode,REFIID riid, LPVOID FAR* lplpvObj); REFIID riid//创建的Com对象的接口标识符
if(FAILED(bResult))
return E_FAIL;
OLE_XSIZE_HIMETRIC hmWidth;//图片的真实宽度
OLE_YSIZE_HIMETRIC hmHeight;//图片的真实高度
pPic-> get_Width(&hmWidth);
pPic-> get_Height(&hmHeight);
//将图形输出到屏幕上(有点像BitBlt)
bResult=pPic-> Render(hDC_Temp,0,0,nScrWidth,nScrHeight,0,hmHeight,hmWidth,-hmHeight,NULL);
pPic-> Release();
CloseHandle(hFile);//关闭打开的文件
if(SUCCEEDED(bResult)) return S_OK;
else return E_FAIL;
}