If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Create window form C++ function using MFC or Win32 API

Hello,

My setup is as follows:
There is function written C++, that must be compiled to DLL. This DLL is linked to some CAD (computer aded design) tool, that has special interface for it.
I want to add to this function some GUI (graphical user interface). So the creation of a window is necessary.
I've tried already with Win32, but without success.
The problem is that CreateWindow function requires application instance handle, that is provided by Windows itself when window is created in "normal conditions".

But to achieve this I commented GetMessage loop. What can be alternative for it ? Unfortunately I'm not programmer, and all this staff I learned/copied from www on-th-fly to get worked my principal project, which is in Verilog.

Re: Create window form C++ function using MFC or Win32 API

I've just tried to do the same using MFC, as creating/processing all of controls with Win32 is complicated.

Why don't you take a working example, get it compile, run it, and understand why that example works?

Learning how to write a Windows API program shouldn't be done by trying to cobble up code yourself. You should be taking a working example already written by an experienced person and understand the different parts of it -- the creation of the window class, the message loop, the window procedure, etc. Writing a Windows program in a proper way cannot be done (I have yet to see it done) without first getting a working example and learning from the example programs.

There are thousands of these examples all over the Internet. Or get a good book, such as the ones written by Charles Petzold.

For example, the GetMessage() loop is documented in again, thousands of places, and more pointedly, MSDN as looking like this:

Re: Create window form C++ function using MFC or Win32 API

Originally Posted by Pavel_47

I've just tried to do the same using MFC, as creating/processing all of controls with Win32 is complicated. Here is a code that doesn't work. Doesn't work means - nothing happens - non window appears:
[...]

Just to mention a little C++ basics detail: app object is locally defined in vpi_CreateWindow function. When it goes out of scope (the function returns), that object is destroyed. So, even something would happen, it happens for a very, very short time.

Originally Posted by Pavel_47

Apart from Win32 and MFC theoretically there is 3rd possibility - WindowsForms. But keeping in mind that this last concept uses CLR, that is unlikely supported by CAD, I won't try this approach.

Sure. To avoid even more painful headaches, in your particular case, keep away of .NET stuff!