Solved

A window created in a dll?

Posted on 2007-11-14
2
302 Views
Last Modified: 2013-11-20
Hi,

Is it possible in a C++ dll to create a window, then give control of that window to the application which uses the dll? Something like:

HWND* CMyDll::DoSomething()
{
    HWND* hwnd = new HWND;
    CreateWindow(hwnd);
    // Set it up for them - where would the window procedure sit etc? Like where do mouse click
    // handlers go? In my dll?

    return hwnd; // now they can control it, and are responsible for deleting it when done.
}

To make things more complex, the group that wants to use this window is using C#, but they are certain that this is possible. Any ideas if it is?

Thanks
0
Comment
Question by:DJ_AM_Juicebox
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 250 total points
ID: 20280872
the short answer is: yes, you can, as far the process that is controlling the window (C#) is the same of the window itself (c++ dll).
in the C# side, the team can create a System.Windows.Forms.Control.FromHandle() control, using the hWnd.
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 250 total points
ID: 20281069
Actually, you can just use



HWND CMyDll::DoSomething()
{
    HWND hwnd;
  g_hInst = hInstance;

  WndClass.cbSize        = sizeof(WNDCLASSEX);
  WndClass.style         = NULL;
  WndClass.lpfnWndProc   = WndProc;
  WndClass.cbClsExtra    = 0;
  WndClass.cbWndExtra    = 0;
  WndClass.hInstance     = g_hInst;
  WndClass.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
  WndClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
  WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  WndClass.lpszMenuName  = NULL;
  WndClass.lpszClassName = g_szClassName;
  WndClass.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

  if(!RegisterClassEx(&WndClass))
  {
     MessageBox(0, "Window Registration Failed!", "Error!",
        MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
     return 0;
  }

  hwnd = CreateWindowEx(
     WS_EX_CLIENTEDGE,
     g_szClassName,
     "The title of my window",
     WS_OVERLAPPEDWINDOW,
     CW_USEDEFAULT, CW_USEDEFAULT, 320, 240,
     NULL, NULL, g_hInst, NULL);


    return hwnd;
}

The WndProc should reside inthe DLL (you won't get a pointer to it otherwise) and there is no need to 'delete' the Window handle - 'DestroyWindow(hwnd);' will take care of that, regardless where that is done.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question