LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating a window through a DLL called through CLFN

Hi, sorry if this is a relatively simple problem but I've been unable to find proper results after a couple hours or so of searching.

 

My group is interacting wtih a DLL that requires a window to draw to. We tried drawing directly to a LabVIEW window (using the FindWindow function through the Windows API), however while that worked we were unable to save the drawn image (the Front panel-> export image invoke node wouldn't save the drawn image). 

 

So, what we did was write some C code and make a wrapper DLL that creates a window to draw to through the CreateWindow function, which we would then export to our main vi (less than ideal, but that's another problem). However, when we call up this wrapper DLL via the CLFN, it won't create the window.  Windows doesn't throw an error, it just won't instantiate the window at all and the function returns an error that the window was never created. The reason I'm posting this problem here instead of a general C++ forum is because we've tested out this wrapper DLL via a test project that imports the DLL and it works fine.

 

This is how I'm setting up the window. I pass the LabVIEW Window found via the FindWindow function in as hInst (sorry for the formatting, I tried the HTML <code> tag and the board doesn't seem to accept it):

 

int initializeWindow(HINSTANCE hInst)
{

    // Initialize global strings
    LoadString(hInst, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
    LoadString(hInst, IDC_WINDOW_CLASS, szWindowClass, MAX_LOADSTRING);
    MyRegisterClass(hInst);

    // Perform application initialization:
    if (!InitInstance (hInst, 1))
    {
        return 0;
    }
    return 1;

}

 

ATOM MyRegisterClass(HINSTANCE hInst)
{
    WNDCLASSEX wcex;

    wcex.cbSize = sizeof(WNDCLASSEX);

    wcex.style            = CS_HREDRAW | CS_VREDRAW | CS_BYTEALIGNCLIENT;
    wcex.lpfnWndProc    = WndProc;
    wcex.cbClsExtra        = 0;
    wcex.cbWndExtra        = 0;
    wcex.hInstance        = hInst;
    wcex.hIcon            = LoadIcon(hInst, MAKEINTRESOURCE(IDI_UVIEW));
    wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground    = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName    = MAKEINTRESOURCE(IDC_UVIEW);
    wcex.lpszClassName    = szWindowClass;
    wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

    return RegisterClassEx(&wcex);
}

 

BOOL InitInstance(HINSTANCE hInst, int nCmdShow)
{
   
   hwnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE | WS_DLGFRAME |  SS_BLACKRECT,
      0, 0, X_WINDOW_SIZE, Y_WINDOW_SIZE, NULL, NULL, hInst, NULL);

   if (hInst == NULL)
   {
        MessageBox(hwnd, TEXT("Problem making instance"), TEXT("ERROR"),0);

        return FALSE;
   }
   if (!hwnd)
   {
      MessageBox(hwnd,TEXT("Problem making window"),TEXT("ERROR"),0);
      return FALSE;
   }

   ShowWindow(hwnd, nCmdShow);
   UpdateWindow(hwnd);

   return TRUE;
}

 

 

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{

 // Standard WndProc implementation.. probably not worth posting all the code unless necessary

}

Does anyone see an obvious problem? Or something I should try?

 

Thanks in advance!

Message Edited by wgerard on 05-16-2010 12:18 AM
0 Kudos
Message 1 of 2
(2,364 Views)

I can be short about that. A Windows HINSTANCE is NOT a HWND by a long stretch. The first is a module handle and the second is ... well yes a window!

 

FindWindow() returns a HWND and you can use that as parent handle for another window, but you can not use it as HINSTANCE ever.

To get at the HINSTANCE for registering new window classes you will need to extract that somehow from the HWND, probably by something like GetWindowLongPtr(.., GWLP_HINSTANCE, ..) or something similar.
But you won't be able to retrieve your own resources from that instance, because it is the instance for the LabVIEW executable, not your DLL.
Message Edited by rolfk on 05-16-2010 10:31 AM
Rolf Kalbermatter
My Blog
Message 2 of 2
(2,346 Views)