[SOLVED] Visual Studio application on Qt
-
Hello,
I have made a program in Visual Studio 2010, and its working well, but on Qt there are some errors. On Qt there is a msvc2010 compiler. I have no idea whats going on here, everything suppose to work.Code:
@#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <iostream>
#include <ole2.h>
#include <olectl.h>
#include "mainwindow.h"
#include <QApplication>bool saveBitmap(LPCWSTR filename, HBITMAP bmp, HPALETTE pal)
{
bool result = false;
PICTDESC pd;pd.cbSizeofstruct = sizeof(PICTDESC); pd.picType = PICTYPE_BITMAP; pd.bmp.hbitmap = bmp; pd.bmp.hpal = pal; LPPICTURE picture; HRESULT res = OleCreatePictureIndirect( &pd, IID_IPicture, false, reinterpret_cast<void**>(&picture)); if(!SUCCEEDED(res)) return false; LPSTREAM stream; res = CreateStreamOnHGlobal(0, true, &stream); if(!SUCCEEDED(res)) { picture->Release(); return false; } LONG bytes_streamed; res = picture->SaveAsFile(stream, true, &bytes_streamed); HANDLE file = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); if (!SUCCEEDED(res) || !file) { stream->Release(); picture->Release(); return false; } HRESULT (__stdcall* dwp)(LPSTREAM,HGLOBAL*)=GetHGlobalFromStream; HGLOBAL mem = 0; dwp(stream,&mem);
GetHGlobalFromStream(stream, &mem);
LPVOID data = GlobalLock(mem); DWORD bytes_written; result = !!WriteFile(file, data, bytes_streamed, &bytes_written, 0); result &= (bytes_written == static_cast<DWORD>(bytes_streamed)); GlobalUnlock(mem); CloseHandle(file); stream->Release(); picture->Release(); return result;
}
bool pstryk(int x, int y, int w, int h, LPCWSTR fname)
{
HDC hdcSource = GetDC(NULL);
HDC hdcMemory = CreateCompatibleDC(hdcSource);int capX = GetDeviceCaps(hdcSource, HORZRES); int capY = GetDeviceCaps(hdcSource, VERTRES); HBITMAP hBitmap = CreateCompatibleBitmap(hdcSource, w, h); HBITMAP hBitmapOld = (HBITMAP)SelectObject(hdcMemory, hBitmap); BitBlt(hdcMemory, 0, 0, w, h, hdcSource, x, x, SRCCOPY); hBitmap = (HBITMAP)SelectObject(hdcMemory, hBitmapOld); DeleteDC(hdcSource); DeleteDC(hdcMemory); HPALETTE hpal = NULL; if(saveBitmap(fname, hBitmap, hpal)) return true; return false;
}
char* zwiekszenie(char *tablica)
{
char licznik[3];
int liczba, liczby[3];
licznik[0]=tablica[7];
licznik[1]=tablica[8];
licznik[2]=tablica[9];
for(int i=0;i<3;i++)
liczby[i]=((int)licznik[i])-48;
liczba=liczby[0]*100+liczby[1]*10+liczby[2];
liczba++;
liczby[0]=(liczba/100)+48;
liczby[1]=((liczba0)/10)+48;
liczby[2]=(liczba)+48;
for(int i=0;i<3;i++)
licznik[i]=(char)liczby[i];
tablica[7]=licznik[0];
tablica[8]=licznik[1];
tablica[9]=licznik[2];
return tablica;
}int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();int i=0; wchar_t plik[15]; char nazwa[]="zdjecie000.bmpp"; for(int i=0;i<10;i++) { mbstowcs(plik,nazwa,15); plik[14]=0; pstryk(0,0,1000,1000,plik); zwiekszenie(nazwa); } return a.exec();
}
@Errors:
@main.obj:-1: błąd:LNK2019: unresolved external symbol imp__GetHGlobalFromStream@8 referenced in function "bool cdecl saveBitmap(wchar_t const *,struct HBITMAP *,struct HPALETTE *)" (?saveBitmap@@YA_NPB_WPAUHBITMAP__@@PAUHPALETTE__@@@Z)
main.obj:-1: błąd:LNK2019: unresolved external symbol imp__CreateStreamOnHGlobal@12 referenced in function "bool cdecl saveBitmap(wchar_t const *,struct HBITMAP *,struct HPALETTE *)" (?saveBitmap@@YA_NPB_WPAUHBITMAP__@@PAUHPALETTE__@@@Z)
main.obj:-1: błąd:LNK2019: unresolved external symbol imp__OleCreatePictureIndirect@16 referenced in function "bool cdecl saveBitmap(wchar_t const *,struct HBITMAP *,struct HPALETTE *)" (?saveBitmap@@YA_NPB_WPAUHBITMAP__@@PAUHPALETTE__@@@Z)
debug\teest.exe:-1: błąd:LNK1120: 3 unresolved externals
@ -
Hi,
Do you link your project to Ole32.lib ?
-
I had not thought about it, because on Visual Studio I didn't link any libraries. But linking solved the problem. I have added:
@#pragma comment(lib, "ole32.lib")
#pragma comment(lib, "OleAut32.lib")
@and now there are no errors.
Thank you very much
-
You're welcome !
Sure you did, you just didn't know about it :) Have a look in the linker properties of your project, you'll see a bunch of libraries already set to be linked.
If you are using a pro file your can also add
@LIBS += -lole32 -lOleAut32@
Since it's working now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)