Solved

Handle for a non-mfc application

Posted on 1997-05-09
4
963 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Suggested Solutions

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

685 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