Solved

Handle for a non-mfc application

Posted on 1997-05-09
4
953 Views
Last Modified: 2013-12-04
Simple - I have a non-mfc windows (95/NT) application that is portable and cannot contain windows-specific code (has 3rd-party GUI/system libs). However in a library I have built I have windows stuff - such as TAPI function calls - and I need to get the application handle. I want to use AfxGetApp, AfxGetInstanceHandle, etc. Everything links OK, but the Afx... functions cause an ASSERT. Do I need to manually initialise some Afx thingy inside my lib?

Alternatively, there's probably a better way to get the apps handle ?

(Forgive me, I've been using mfc too long and my brain has gone mushy.)

Thanx in advance
0
Comment
Question by:TimeLord
  • 2
4 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 1397219
Using AfxGetApp, AfxGetInstanceHandle, etc in a non-mfc application is not good because you have to initialize many variables yourself. You can check MFC source code. The better way is to just get the instance handle in WinMain(). Record the instance handle and transfer it to your lib.
0
 

Author Comment

by:TimeLord
ID: 1397220
Ah, no-can-do. I am sort-of familiar with the WinMain technique; however, that is windows-specific (and anyway the automatic code generator from the 3rd-party GUI tool generates a portable 'main', not a WinMain).

And of course I can't put WinMain in my library... there must be another way?? I mean, the 3rd-party libs must have windows handles for internal use when the code is being compiled for a PC...
0
 
LVL 3

Accepted Solution

by:
Melange earned 100 total points
ID: 1397221
Is your windows library a DLL? You'll need to make sure that is a self-contained MFC DLL and not an extension DLL. Then the DLL will have a self-contained CWinApp from which you can use AfxGetApp, AfxGetInstanceHandle, etc. Failing that you can simple call "GetModuleHandle" with NULL as the parameter to retrieve the applications HMODULE handle (equivalent to HINSTANCE).
0
 

Author Comment

by:TimeLord
ID: 1397222
No, just a normal .lib. The GetModuleHandle function works just fine and you saved me some time stuffing around. Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

914 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now