Home > Software engineering >  Write a DLL, use the MFC CImage class, but after the c # call DLL, in the XP system, abnormal CImage
Write a DLL, use the MFC CImage class, but after the c # call DLL, in the XP system, abnormal CImage

Time:10-24

 CImage imgPic;//exception statement 
//AfxMessageBox (to_string (3). C_str ());
ImgPic. Create (PicWidth PicHeight, 24);

On atlimage. H file tracking debugging, found that the constructor invokes the following this statement, the code in 441 lines
 static CInitGDIPlus * GetInitGDIPlusInstance () 
{
The static CInitGDIPlus gdiPlus;
Return & amp; GdiPlus;
}

Among them, the static CInitGDIPlus gidPlus; Statement is unusual, has failed to into CInitGDIPlus constructor; The following is a function of CInitGDIPlus, CImage class, in the line 100
 class CInitGDIPlus 
{
Public:
Throw CInitGDIPlus () ();
~ CInitGDIPlus throw () ();

Bool Init () throw ();
Void ReleaseGDIPlus throw () ();
Void IncreaseCImageCount throw () ();
Void DecreaseCImageCount throw () ();

Private:
ULONG_PTR m_dwToken;
CRITICAL_SECTION m_sect;
LONG m_nCImageObjects;
DWORD m_dwLastError;
};

I'm trying to keep static gdiPlus into non-static CInitGDIPlus gdiPlus, no problem. Use the static int I; No problems with the tests,
But with more static, given the strength of my questions, don't trust to
Apes and old to want to seek advice, what's the solution?

Additional: this DLL, OCX in call, then call OCX, IE CImage also can appear this problem, the key only XP SP2/3 system, other systems is to use the

CodePudding user response:

Whether the XP GDIPlus. DLL missing or version does not match?

CodePudding user response:

reference 1st floor zgl7903 response:
if XP GDIPlus. DLL missing or version does not match?
unlikely, I tried the MFC to write a test case call DLL, in XP system is ok, just saying c # call or page calls OCX encapsulation will produce problems; And I can remove the static is normal constructor and destructor; I doubted in is called the environment, but copy to system32 folder or in the same situation

CodePudding user response:

You're much more likely that GDI + uninitialized, own plus an initialization operation
 
# include & lt; Atlimage. H>
//global variable
Struct _tagGdiplsInit_t
{
ULONG_PTR m_dwToken;
_tagGdiplsInit_t ()
{
Gdiplus: : GdiplusStartupInput input;
Gdiplus: : GdiplusStartupOutput output;
VERIFY (S_OK==Gdiplus: : GdiplusStartup (& amp; M_dwToken, & amp; Input, & amp; The output));
}
~ _tagGdiplsInit_t ()
{
Gdiplus: : GdiplusShutdown (m_dwToken);
}
} m_GdipInit;



CodePudding user response:

reference zgl7903 reply: 3/f
there is no likelihood of that GDI + initialization is bigger, own plus an initialization operation
 
# include & lt; Atlimage. H>
//global variable
Struct _tagGdiplsInit_t
{
ULONG_PTR m_dwToken;
_tagGdiplsInit_t ()
{
Gdiplus: : GdiplusStartupInput input;
Gdiplus: : GdiplusStartupOutput output;
VERIFY (S_OK==Gdiplus: : GdiplusStartup (& amp; M_dwToken, & amp; Input, & amp; The output));
}
~ _tagGdiplsInit_t ()
{
Gdiplus: : GdiplusShutdown (m_dwToken);
}
} m_GdipInit;


This time I go to add a try,
But, according to this article I see https://blog.csdn.net/sha276793422/article/details/40302993, and practice my tracking, GDI + bool he is in the function to initialize the Init () throw (); And not on the constructor initialization; And it is initialized when the load or save the GDI +.
  • Related