Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Visual Studio application on Qt
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Visual Studio application on Qt

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Arthiego90
    wrote on last edited by
    #1

    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&#40;stream, true, &bytes_streamed&#41;;
    
    HANDLE file = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0&#41;;
    
    if (!SUCCEEDED(res&#41; || !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&#40;file, data, bytes_streamed, &bytes_written, 0&#41;;
    result  &= (bytes_written == static_cast<DWORD>(bytes_streamed&#41;);
    
    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&#40;&#41;;
    

    }
    @

    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
    @

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Do you link your project to Ole32.lib ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Arthiego90
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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 :)

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved