|
VC6 -> VC2005 is a huge difference, VC6 was not very standards compliant at all. MFC has not changed that much, however.
Software_Specialist wrote: How can i step through the whole program...Break point isnt helping me out.
Run in debug mode ?
Software_Specialist wrote: But if i just write TProgressBar in place of CProgressCtrl
Obviously if they are different classes, they will expose different methods and you will get errors.
Moving from one framework to another is essentially a rewrite.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
i am using picturebox to create visual buttons, but i want the picturebox has tabstop property, how can i do?
any api function ??
|
|
|
|
|
Try overiding the WM_GETDLGCODE message of the picture box and return DLGC_WANTTAB.
nave
|
|
|
|
|
i am gladly pleased you
|
|
|
|
|
In Test.exe module the application class CTestApp was derived from CWinApp . Everything worked fine. Then I decided to move some common stuff from CTestApp to CCommonApp . This CCommonApp is defined in Util.dll module. Now CTestApp is derived from CCommonApp which is derived from CWinApp .
The contructor of CTestApp is called properly and all its parent contructors. However the application crashes right after this, because the AfxGetApp returns NULL in MFC core and can't call InitApplication method.
Any idea what can be the problem?
Thanks, Abyss
|
|
|
|
|
You'll still need a global app object in the EXE project, something like:
// The one and only CTestApp object
CTestApp theApp;
If you already have that...
How is CCommonApp declared? It should be like this:
class AFX_EXT_CLASS CCommonApp : public CWinApp
{
...
};
Your DLL needs to be a legitimate MFC extension DLL as well.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Thanks for advice.
I have this global application object in EXE. My DLL is also a dynamic DLL, where the CCommonApp is exported using __declspec(dllexport) and imported in EXE using __declspec(dllimport) .
I'm not sure what did you mean by legitime MFC extension DLL.
My Util.dll project has its own CUtilApp : CWinApp class, and _USRDLL define in project settings. Also tried to use DllMain method with _AFXEXT define. It did not help .
Maybe something is wrong with project settings, maybe something else. But I have no idea what could be wrong.
Thanks, Abyss
|
|
|
|
|
Abyss wrote: I'm not sure what did you mean by legitime MFC extension DLL.
See Extension DLLs[^]
Classes derived from MFC classes in a DLL and then derived from in an EXE means the DLL MUST
be an MFC extension DLL. MFC requires certain initialization in DllMain() and import/export
properties on classes must be dealt with. It's all documented at the link (and sublinks) above.
Also important - you can't statically link to MFC libraries - the DLL and the EXE need to use the
shared MFC DLL library.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Well, I tried to generate these two projects from scratch using VS Wizard. The EXE application is a simple MFC non doc-view architecture module. The DLL is a MFC Extension module. I added my CCommonApp class to the DLL and exported using AFX_EXT_CLASS macro. In EXE I replaced CWinApp with CCommonApp .
The result is the same
Now I would say that this is not supported. However I can remember that in the past I saw several projects where it worked well (unfortunately I can't find them)...
Any help is appreciated.
Thanks, Abyss
|
|
|
|
|
I found the culprit. My project is base on Multibyte character set. When I introduced the new DLL module it was set to unicode character set by default. And this caused the whole problem - different MFC libraries where linked to my modules. It was enough to switch the project to Multibyte char. set and it started to working.
It does not matter if the DLL is MFC Extension or Regular DLL. In both cases it works fine.
Thanks for your help.
Abyss
|
|
|
|
|
Cool! Glad you found it!
Abyss wrote: It does not matter if the DLL is MFC Extension or Regular DLL. In both cases it works fine.
It will probably matter eventually - the initialization in the extension DLL is important to many
of the MFC classes. It just depends which ones you use and where The CWinApp class is one of
them - it's initialization in the DLL module is used with window/dialog creation for example.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Hi I'm trying to call a function in a DLL and am having trouble doing so because it uses callback and I need the function in the DLL to write to my dialog.
The function prototype is like this:
<br />
UINT CALLBACK PatchApply(LPSTR lpszCmdLine,LPVOID (CALLBACK *lpfCallBack)(UINT Id, LPVOID lpParm),BOOL WaitFlag);
and the example given is in C and not C++ (i'm making a dialog based program in unmanaged VC++ 7
Example snippet :
<br />
typedef LPVOID (CALLBACK* PATCHCALLBACK)(UINT, LPVOID);<br />
<br />
UINT CALLBACK PatchApply( LPSTR CmdLine, <br />
PATCHCALLBACK CallBackFn, <br />
BOOL WaitFlag);<br />
<br />
LPVOID CALLBACK __export CallBack( UINT Id, LPVOID Parm );<br />
My callback function is declared as
LPVOID CALLBACK CallBack(UINT Id, LPVOID Parm);<br />
and in the callback program I try to write to a listbox on my dialog.
Prior to calling I do like this:
<br />
typedef LPVOID (CALLBACK* PATCHCALLBACK)(UINT, LPVOID);<br />
PATCHCALLBACK CallBackPtr; <br />
CallBackPtr = MakeProcInstance((FARPROC) CallBack, AfxGetInstanceHandle());<br />
<br />
nRetCode = PatchApply(lpszBuf, CallBackPtr, TRUE);<br />
The MakeProcInstance is also from example and I try to call the PatchApply function directly from the DLL as I link the lib file into my program.
I get this error "cannot convert from 'overloaded-function' to 'FARPROC'" with above code and don't know what to do
Can anyone tell med what I need to do to call this succesfully ?
Thanks
|
|
|
|
|
Well, one thing is that FARPROC is defined as
typedef INT_PTR (WINAPI *FARPROC)(void);<br />
whereas your callback function has a return type of LPVOID .
So it looks like you're trying to redefine the return type of the callback function when you cast it to (FARPROC) in the call to MakeProcInstance .
Also, FARPROC has no arguments, so it is a very different function signature.
-- modified at 13:32 Sunday 27th May, 2007
--------------------------------
"All that is necessary for the forces of evil to win in the world is for enough good men to do nothing" -- Edmund Burke
|
|
|
|
|
Hi all:
My program crashed at the line:
for (vector<int>::iterator it = list.begin(); it != list.end(); ++it) {
if (*it < 0) list.erase(it);
}
//Filtering out all the negative numbers from a vector.
I am sure that it is vector::erase(it) is causing all the pain, but not sure how to fix.
Can anyone help?
Thank you
|
|
|
|
|
When you call erase, it will invalidate your current iterator and all iterators that follow. Thus, when you erase something and try to increment this same iterator, this will cause an exception. The erase function returns an iterator to the next valid element, you need to use that.
Try to change your code to something like this:
while (it != list.end())<br />
{<br />
if (*it<0)<br />
{<br />
it = erase(it);<br />
}<br />
else<br />
it++;<br />
}
|
|
|
|
|
Thank you very much, it worked.
|
|
|
|
|
Cedric's given you an answer, and its good that it works - here's another way - include <algorithm> and use remove_if ..
the following link shows how :-
http://support.microsoft.com/kb/156532[^]
'g'
|
|
|
|
|
Hi 'g':
Thank you very much for bringing that into attentaion as well.
I have learnt a lot from both of you.
Thank you
|
|
|
|
|
dear friends,
i am encountering a strange problem.
i have built a DLL containing a MFC Dialog in which i have inserted an active X component - Date Time Picker control.
when i try to call this dialog from my main application
the dialog doesnot appear at all.
i tried with simple MFC Dialog based exe it works fine.
can any one of you guide me on this
thanks and regards
prashant
|
|
|
|
|
have you put AFX_MANAGE_STATE( AfxGetStaticModuleState()); in dll before creating the dialog?
nave
|
|
|
|
|
hi naveen,
yes i have added the above macro correctly.
can you please try it once, and tell me if it works
thanks and regards
prashant
|
|
|
|
|
can you show me how you called the dialog from the exe?
prash pissey wrote: can you please try it once, and tell me if it works
nave
|
|
|
|
|
hi naveen,
here is he code
extern "C" __dllspec(dllexport) void CallDate()
{
AFX_MANAGE_STATE( AfxGetStaticModuleState());
CDateTimeDlg DateTimeDlg;
DateTimeDlg.DoModal();
}
thanks and regards
prashant
|
|
|
|
|
did u try removing that activex from the dialog?
where did u get this datetimectrl ActiveX? Is it the normal Date Time control among the windows common controls?
nave
|
|
|
|
|
hi nave,
it is Microsoft Date Time Picker control.
open VC++ go to dialog editor ,
right click, you will get a menu,
select "insert Active X",
a list of Active x components will appear.
in the list select "Microsoft Date Time Picker Control".
i have tried to remove the active X component and calling the DLL dialog.
then the dialog appears,works fine.
i suspect that acive x is causing the problem
thanks and regards
prashant
thanks and
|
|
|
|