Board index » Visual Studio » GetDC() Fails in DLL.

GetDC() Fails in DLL.

Visual Studio86
I have created SDI Application and one DLL.

I am dynamically loading DLL.



I am passing View Pointer to DLL,

and then I try to get DC from View using GetDC() function.

But GetDC() is returning NULL , also GetLastError() is returning 0.



This Code is working Fine in Debug Mode but only gives problem in

Release Mode.

Here is snap shot of my DLL Function.

BOOL Initialize(CWnd* pWnd)

{

CDC* hDC = pWnd->GetDC();

}



I am using __cdecl calling convetions which I have set in Projects

Settings of Visual Studio.



Thanks,

Avinash


-
 

Re:GetDC() Fails in DLL.

Quote
I have created SDI Application and one DLL.

I am dynamically loading DLL.



I am passing View Pointer to DLL,

and then I try to get DC from View using GetDC() function.

But GetDC() is returning NULL , also GetLastError() is returning 0.



This Code is working Fine in Debug Mode but only gives problem in

Release Mode.



Avinash,



Are you mixing a release mode DLL with a debug mode EXE?



If you are, that will be the problem, you can't mix them. To free

yourself from that situation (unless your design requires you to pass

such objects between the DLL/EXE), I suggest that you pass a native

HWND rather than the MFC class wrapper CWnd *.



Dave

--

MVP VC++ FAQ: www.mvps.org/vcfaq">www.mvps.org/vcfaq

-

Re:GetDC() Fails in DLL.

Are you using static linking? If so, this would be the problem, because the DLL and the

application have separate handle maps. Use the shared MFC DLL.



There is rarely a need to call GetDC(); you would typically write

CClientDC dc(pWnd);

to get the DC. That, too, will fail if you are using static linking.

joe



On 3 Sep 2004 00:14:44 -0700, avimandale@india.com (Avin) wrote:



Quote
I have created SDI Application and one DLL.

I am dynamically loading DLL.



I am passing View Pointer to DLL,

and then I try to get DC from View using GetDC() function.

But GetDC() is returning NULL , also GetLastError() is returning 0.



This Code is working Fine in Debug Mode but only gives problem in

Release Mode.

Here is snap shot of my DLL Function.

BOOL Initialize(CWnd* pWnd)

{

CDC* hDC = pWnd->GetDC();

}



I am using __cdecl calling convetions which I have set in Projects

Settings of Visual Studio.



Thanks,

Avinash



Joseph M. Newcomer [MVP]

email: newcomer@flounder.com

Web: www.flounder.com">www.flounder.com

MVP Tips: www.flounder.com/mvp_tips.htm">www.flounder.com/mvp_tips.htm

-

Re:GetDC() Fails in DLL.

Thanks Joseph,

It works fine after I have changed settings to "Use MFC in Shared

DLL."



I am facing new problem now. My application works fine in Release

Mode, but

In Debug Mode, when I call GetDC() on a receivd Window Pointer in DLL,

I get an Debug Assertion. This is assertion is in IsWindow(),

in AfxWin2.inl on Line 112.



Is there any way to avoid this Assertion, so that I can run my (App +

DLL) in debug mode also.



Thanks in advance. Please let me know if you require more information

about my program.



thanks

Avinash







Joseph M. Newcomer <newcomer@flounder.com>wrote in message news:<3v4hj01ikbadc4968jlf5eh09v3aeaj51k@4ax.com>...

Quote
Are you using static linking? If so, this would be the problem, because the DLL and the

application have separate handle maps. Use the shared MFC DLL.



There is rarely a need to call GetDC(); you would typically write

CClientDC dc(pWnd);

to get the DC. That, too, will fail if you are using static linking.

joe



On 3 Sep 2004 00:14:44 -0700, avimandale@india.com (Avin) wrote:



>I have created SDI Application and one DLL.

>I am dynamically loading DLL.

>

>I am passing View Pointer to DLL,

>and then I try to get DC from View using GetDC() function.

>But GetDC() is returning NULL , also GetLastError() is returning 0.

>

>This Code is working Fine in Debug Mode but only gives problem in

>Release Mode.

>Here is snap shot of my DLL Function.

>BOOL Initialize(CWnd* pWnd)

>{

>CDC* hDC = pWnd->GetDC();

>}

>

>I am using __cdecl calling convetions which I have set in Projects

>Settings of Visual Studio.

>

>Thanks,

>Avinash



Joseph M. Newcomer [MVP]

email: newcomer@flounder.com

Web: www.flounder.com">www.flounder.com

MVP Tips: www.flounder.com/mvp_tips.htm">www.flounder.com/mvp_tips.htm

-

Re:GetDC() Fails in DLL.

Avin wrote:

Quote
Thanks Joseph,

It works fine after I have changed settings to "Use MFC in Shared

DLL."



I am facing new problem now. My application works fine in Release

Mode, but

In Debug Mode, when I call GetDC() on a receivd Window Pointer in DLL,

I get an Debug Assertion. This is assertion is in IsWindow(),

in AfxWin2.inl on Line 112.



Is there any way to avoid this Assertion, so that I can run my (App +

DLL) in debug mode also.



Thanks in advance. Please let me know if you require more information

about my program.



thanks

Avinash



It might be educational to know if IsWindow() also fails in your release

build. Have you tried adding this check as an experiment?



If the debug build fails in IsWindow() then it is very likely that you

have a coding bug. There is probably a very good reason that the

assertion fails. The way to "avoid" this assertion is to analyze why it

fails and correct the bug. The most common cause is attempting to use a

CWnd before its HWND member (m_hWnd) has been initialized with a valid

window handle.



--

Scott McPhillips [VC++ MVP]



-