Hi again, I have been trying to make the application Instance truly global
(ie declaring it in my applications main header file for use in seperate C++
files). It works fine the way tha app is initially set up with it being made
global only to the C++ file that is initially created but when i try to make
it truly global I get the compilation error :

StdAfx.obj : error LNK2005: "struct HINSTANCE__ * g_hInst"
(?g_hInst@@3PAUHINSTANCE__@@A) already defined in mclient.obj

stdafx.h is included from both dlgprocs.cpp and mclient.cpp, the two C++
files I wish to use it from at present, and stdafx.h includes the file
mclient.h (the header file containing the global definition of g_hInst). I
believe this may be a problem regarding the way C++ handles includes
differently to C ? I haven't done much C++ before and my application is
basically written in C as this is what I am used to and I am not at all
familiar with the C++ standard, if anyone could point out how this could be
solved or point me in the right direction of any help it would be greatly
appreciated!
Thanks in advance.
Matt

Re: Global Instance by Bruce

Bruce
Sun Jul 25 17:35:29 CDT 2004

Well, seeing how you are declaring it would be helpful.

But I suspect that you need to become familiar with "extern" From your
description, it sounds like you are declaring it in the header file, which
is bad. It should be extern in the header and declared in *one* C/C++ file.

--
Bruce Eitman (eMVP)
Senior Engineer
beitman AT applieddata DOT net

Applied Data Systems
www.applieddata.net
An ISO 9001:2000 Registered Company
Microsoft WEP Gold-level Member




Re: Global Instance by Matthew

Matthew
Sun Jul 25 17:55:03 CDT 2004

Thanks for the reply, here is the definition in the header file :
HINSTANCE g_hInst;
basically the same as from the main C++ file and cut/pasted into the header,
obviously this is not a good way to do it so I will look into using extern,
if anyone has any more ideas based on this info please chuck them in, all
help greatly appreciated.
Cheers
Matt


"Bruce Eitman (eMVP)" <beitmannospam@NOSPAM_applieddata.NOSPAM_net> wrote in
message news:O9XkxepcEHA.2840@TK2MSFTNGP11.phx.gbl...
> Well, seeing how you are declaring it would be helpful.
>
> But I suspect that you need to become familiar with "extern" From your
> description, it sounds like you are declaring it in the header file, which
> is bad. It should be extern in the header and declared in *one* C/C++
file.
>
> --
> Bruce Eitman (eMVP)
> Senior Engineer
> beitman AT applieddata DOT net
>
> Applied Data Systems
> www.applieddata.net
> An ISO 9001:2000 Registered Company
> Microsoft WEP Gold-level Member
>
>
>



Re: Global Instance by Bruce

Bruce
Sun Jul 25 20:09:15 CDT 2004

In your main c++ file:

HINSTANCE g_hInst;

in you header file:

extern HINSTANCE g_hInst;


--
Bruce Eitman (eMVP)
Senior Engineer
beitman AT applieddata DOT net

Applied Data Systems
www.applieddata.net
An ISO 9001:2000 Registered Company
Microsoft WEP Gold-level Member




Re: Global Instance by Matthew

Matthew
Sun Jul 25 23:15:10 CDT 2004

Thanks for the help, its starting to make sense now, seems to be working as
well which is always a bonus considering how long i have left to complete
the project!
Thanks again!
Matt

"Bruce Eitman (eMVP)" <beitmannospam@NOSPAM_applieddata.NOSPAM_net> wrote in
message news:Ol1xs0qcEHA.996@TK2MSFTNGP12.phx.gbl...
> In your main c++ file:
>
> HINSTANCE g_hInst;
>
> in you header file:
>
> extern HINSTANCE g_hInst;
>
>
> --
> Bruce Eitman (eMVP)
> Senior Engineer
> beitman AT applieddata DOT net
>
> Applied Data Systems
> www.applieddata.net
> An ISO 9001:2000 Registered Company
> Microsoft WEP Gold-level Member
>
>
>