|
sashoalm wrote: The MFC dll is linked to a different CRT than the exe.
I hope you know what you're doing there.
For more info on what you can/can't do with MFC DLLs:
Kinds of DLLs[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
No problem there. We're using vc6 with mfc 4.2. You'd have to be running Windows 3.1 not to have the dlls (ok Windows 95)
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
I have no idea what you're talking about.
I'm talking about mixing CRT libraries between DLLs and EXEs.
I'm not sure what a DLL has to do with this anyway, unless your InitInstance
is in the DLL, in which case the commandline stuff will probably fail
if the DLL is using a different CRT.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: I have no idea what you're talking about.
I thought you were talking about having to redistribute the MFC DLLs.
Sorry about the misunderstanding. I've written in my earlier post 'The MFC dll is linked to a different CRT than the exe'. I meant 'The MFC dll might be linked' and the error might come because of this. Otherwise why would it be correct in my InitInstance, then stop being correct when I step into ParseCommandLine?
I was thinking that there are two copies of __argc and __argv, one for the EXE and one for the MFC DLLs, and ParseCommandLine looks at a different variable. I've had a similar problem when I used a static variable in a function that was inside the class body. I had the variable correctly initialized in one cpp file, then when the function was called from another cpp file, the variable was uninitialized. I found out that I didn't have a single static variable, instead I had a different static variable for each cpp file where the function was invoked.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
sashoalm wrote: I was thinking that there are two copies of __argc and __argv, one for the EXE and one for the MFC DLLs
Yes, if the DLL is linked to a different CRT than the EXE.
That's why I stated I hope you know what you're doing there
If you mix different versions of MFC and/or the CRT in one process,
then you need to make sure you know what's going on - for example, you can't
allocate an object using "new" in A DLL and try to delete the object in
the EXE if they are using different CRTs. Also you need to be sure initialization
of MFC and the CRT are done properly in the DLL.
The link in my first reply describes those scenarios so you can mix MFC/CRT
properly.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I copy/pasted the code of ParseCommandLine in my own CWinApp-derived class, and now it works fine. It seems that the __argc visible from my code and the __argc visible from APPCORE.CPP are two different variables, but I'm still not sure if I have different CRTs. My project is not a dll, and using MFC as a shared DLL is the default in AppWizard. The only thing I've tweaked is setting the CRT to multithreaded dll instead of singlethreaded. Do you have any suggestions how to find out if I have different CRTs? That would be very helpful.
As for the different variables, actually the __argc visible from APPCORE.CPP is a mess of macros and function pointers, and the __argc visible from my code is a variable. Here's the code in MFC about __argc/__argv
#if defined(_DLL) && defined(_M_IX86)
#define __argc (*__p___argc()) /* count of cmd line args */
#define __argv (*__p___argv()) /* pointer to table of cmd line args */
_CRTIMP int * __cdecl __p___argc(void);
_CRTIMP char *** __cdecl __p___argv(void);
#else
_CRTIMP extern int __argc;
_CRTIMP extern char ** __argv;
#endif
#define AFNAME(var) __p_ ## var
#define AFRET(var) &var
_CRTIMP int * __cdecl
AFNAME(__argc) (void)
{
return AFRET(__argc);
}
#define AFRET(var) &var
It looks very complicated.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
sashoalm wrote: My project is not a dll, and using MFC as a shared DLL is the default in AppWizard. The only thing I've tweaked is setting the CRT to multithreaded dll instead of singlethreaded.
Are you mixing a non-debug multithread CRT DLL with the
debug version of MFC? If so, then there would be two CRTs.
You need to make sure you're using the same CRT library as the
MFC library is using.
You can see what DLLs are loaded int the output window when you run
in the debugger.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I found a flag in my linker options - /nodefaultlib:"msvcrtd.lib", after removing it CWinApp::ParseCommandLine works.
But the linker now gives me a warning:
LINK : warning LNK4098: defaultlib "MSVCRT" conflicts with use of other libs; use /NODEFAULTLIB:library
Is this warning a problem?
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
I imagine you're linking a library which is trying to link a
different CRT version.
All warnings are problems IMO.
If it were me, I'd definitely track it down and try to fix it.
If you use the app wizard to create a temporary MFC project,
you'll get a good default set of settings. Compare those to yours...
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I'm not sure what the cause is exactly but I may be able to offer some help finding it. Clearly you're using MFC and ParseCommandLine is going to be relying on the MFC startup code to provide it with the command line data. This in turn will be getting the data from the C Runtime startup code which runs before MFC gets started. This code in turn gets the command line arguments from the Windows Portable Executable Loader which gets them from the actual 'command line' via Windows itself.
Somewhere a link in this chain has broken and no command line parameters have been stored or passed on to the next stage.
I would start by tracking back the C Runtime startup code to a point where the command line is available e.g. __mainCRTStartup and then track it forward to find where the broken link is. I strongly suspect it will be between the C Runtime and MFC, probably because you need to call some MFC startup code that you aren't calling before calling ParseCommandLine.
"The secret of happiness is freedom, and the secret of freedom, courage."
Thucydides (B.C. 460-400)
|
|
|
|
|
Matthew Faithfull wrote: Somewhere a link in this chain has broken and no command line parameters have been stored or passed on to the next stage
But CWinApp::m_lpCmdLine shows the command line I give correctly. Could it be that ParseCommandLine tries to get it's params from a different avenue?
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
Yes, it looks like it might be going back to the CRT which may have had its copies deleted for some reason by this stage. If MFC has the data you want then as a last resort you could simply write/override your own function to access it.
"The secret of happiness is freedom, and the secret of freedom, courage."
Thucydides (B.C. 460-400)
|
|
|
|
|
Hi all i am new to vc++.
In my application i want to change the textcolor in the combobox dynamically is there a way by which i can do this????
Thanks in advance...
|
|
|
|
|
Yeah sure there is, though if the control exists on a dialog you have more limited options when it comes to easily colouring the background.
If the control exists on a dialog, you may have the following code inside your DialogProc
case WM_CTLCOLORLISTBOX:
SetTextColor((HDC)wParam, RGB(250, 100, 0));
return TRUE;
If the control exists on a normal window, you can return a handle to the brush used to draw the background.
case WM_CTLCOLORLISTBOX:
SetTextColor((HDC)wParam, RGB(250, 100, 0));
return GetStockObject(LTGRAY_BRUSH);
on receipt of the message, lParam = the HWND of the list box. You may want to check the value of this param if you have more than one list/combo box and you'd like them to have different colours.
|
|
|
|
|
How can i convert MFC datetime to MFC string? Thank you.
|
|
|
|
|
|
Hi everybody, need to view pictures that have tif format, by using CImage class.Any idea will be appriciated. Thanks.
|
|
|
|
|
Documentation says
CImage Class
CImage provides enhanced bitmap support, including the ability to load and save images in JPEG, GIF, BMP, and Portable Network Graphics (PNG) formats.
I cant see TIFF in the list
What about Image class of GDI+??
Or you don't/can't use GDI+??
I hope it helps..
Regards,
Sandip.
|
|
|
|
|
thaks for your reply i am only allowed to use CImage class
|
|
|
|
|
susanne1 wrote: thaks for your reply i am only allowed to use CImage class
In this case this article might help you
Transparent Bitmap
Regards,
Sandip.
|
|
|
|
|
SandipG wrote: I cant see TIFF in the list
The docs are incorrect.
CImage uses GDI+ to load images, and TIFF images are supported.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: CImage uses GDI+ to load images, and TIFF images are supported.
Is it?? Thanks I didn't know.
Mark Salsbery wrote: The docs are incorrect.
I checked it with MSDN.. I should be careful next time..
Thanks for the information.
Regards,
Sandip.
|
|
|
|
|
SandipG wrote: I checked it with MSDN.
I checked it by writing code and testing it
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: I checked it by writing code and testing it Poke tongue
Regards,
Sandip.
|
|
|
|
|
What are you having problems with?
Here's a little example...
CImage img;
img.Load(_T("C:\\somepath\\some.tif"));
CClientDC dc(pWnd);
img.Draw(dc, 0, 0);
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|