|
I'm trying to use some unmanaged legacy code with my managed application
and I need to include some windows headers ( afxwin.h, afxtempl.h, mmsystem.h ) in stdafx.h but there are some conflicts with some .net framework API, for example, the System::Windows::Forms::MessageBox can't be compiled :
...
#using <System.Windows.Forms.dll>
using namespace System::Windows::Forms;
...
System::Windows::Forms::MessageBox::Show(s, S"Received String");
gives :
<br />
c.cpp(130) : error C2039: 'MessageBoxA' : is not a member of 'System::Windows::Forms'<br />
c.cpp(130) : error C2660: 'System::Windows::Forms::Control::Show' : function does not take 2 parameters<br />
If I removed the legacy code and the headers, everything is ok ...
Any thought ? nish ? ( as you are the expert ! )
Thanks.
Max.
here's the sample code... ( from basic generated managed project. )
#include <afxwin.h>
#include <afxtempl.h>
#ifndef _INC_MMSYSTEM
#pragma message("To avoid this message, please put mmsystem.h in your PCH")
#include <mmsystem.h>
#endif
#include "stdafx.h"
#using <mscorlib.dll>
#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
#include <tchar.h>
using namespace System;
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace System::ComponentModel;
int _tmain(void)
{
MessageBox::Show(S"Allo", S"Request");
Console::WriteLine(S"Hello World");
return 0;
}
|
|
|
|
|
The problem is that windows.h #define's "MessageBox" to be either "MessageBoxA" (ANSI) or "MessabeBoxW" (Unicode). The preprocessor is replacing all instances of "MessageBox" in your code to "MessageBoxA", and of course that is not a valid type in the Forms namespace.
You must #undef MessageBox.
If you intend to use both the Windows MessageBox() and the .NET Framework's MessageBox(), you can get tricky and store the MessageBox macro on the preprocessor's stack:
#pragma push_macro("MessageBox")
#undef MessageBox
...
#pragma pop_macro("MessageBox")
This posting is provided “AS IS” with no warranties, and confers no rights. You assume all risk for your use. © 2001 Microsoft Corporation. All rights reserved.
|
|
|
|
|
Nick Hodapp (MSFT) wrote:
You must #undef MessageBox.
That did the trick, but it's not something I really like ...
Thanks.
Max.
|
|
|
|
|
Me neither, but it's the reality of programming with libraries that have conflicting names...
Nick
This posting is provided “AS IS” with no warranties, and confers no rights. You assume all risk for your use. © 2001 Microsoft Corporation. All rights reserved.
|
|
|
|
|
I don't think the problem is the conflicting named, I can live with that, but the problem is with the preprocessor that rewrite code for us ...
Max.
|
|
|
|
|
Well, that's just C++.
This posting is provided “AS IS” with no warranties, and confers no rights. You assume all risk for your use. © 2001 Microsoft Corporation. All rights reserved.
|
|
|
|
|
Wouldn't solving conflicting names with simple rules a real interesting stuff to come up with ?
If I remember well, the Eiffel language has this feature, when deriving classes.
And I swallow a small raisin.
|
|
|
|
|
Hi, everyone!
Look at the source codes,
--------
/* #define WIN32 */
#ifdef WIN32
#define MORECORE wsbrk
#endif
--------
Such is the comments,
--------
WIN32 (default: undefined)
Define this on MS win (95, nt) platforms to compile in sbrk emulation.
--------
I have two questions,
1. What means WIN32? When the variable "WIN32" becomes
defined? When it is not defined?
2. What means "sbrk" in the comment? What means "wsbrk"?
Btw: the software is written for both Windows and Linux
platforms.
Cheers,
George
|
|
|
|
|
Please only post in one forum...
This question don't have anything to do with either Managed C++ or ATL/WTL/STL
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Thanks, Anders pal!
I will accept your advice.
I cross-posted because my boss is asked me to hand in the
project immediately, but I am in trouble as you
see.
Cheers,
George
|
|
|
|
|
Hi, everyone!
I have searched the help page for "size_t" but failed
to find the help page and information about "size_t".
Where can I find the help page or information about
"size_t"? Can you paste detailed information about
"size_t".
Thanks.
Cheers,
George
|
|
|
|
|
|
Thanks, Nish, my old friend!
I still have a question.
What means "typedef _W64 unsigned int size_t;"?
Does it mean the three objects
_W64, unsigned int and size_t are the same?
Have a nice weekend,
George
|
|
|
|
|
Hello George
It means size_t is a synonym for _W64 unsigned int
And as far as I could make out _W64 has been defined as nothing. Perhaps someone else can correct me here if I am wrong.
So as far as you are concerned you can cast the size_t to an unsigned int
Regards,
Nish
p.s. I found the cross posts humorous, specially your choice of the ATL/WTL forum
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Review by Shog9
Click here for review[NW]
|
|
|
|
|
Thanks, Nisk pal!
I think I have fully understood the meaning
of size_t under your directions and other pals
in ATL/WTL forum.
Have a nice weekend,
George
|
|
|
|
|
As far as I can see, there's no header file in Managed C++ ?!?!?!?! everything seems to be inlined in the class like this in either a .h or .cpp file that can be included in the main project file:
<code>
__gc public class MyForm : public Form
{
public:
MyForm()
{
Text = S"MyForm";
};
};
</code>
The question, is, can I separate the implementation for the declaration ? to have a header file and a code file ( .h and .cpp ) ?
Are there rules, guidelines or specification ?
Thanks.
Max.
|
|
|
|
|
|
when i use that function (AfxGetInstanceHandle())in managed class i got an exception i do not know how to handle it plz help me.
r00d0034@yahoo.com
|
|
|
|
|
|
first of let me tell u what i am tring to do .
i am trying to convert a vc++ app into dot net.that program is related to mouse and keyboard hooks.
it return HINSTANCE.i know what i do mostly.
i did not initialize MFC from an MC++ app.plzz tell how to do it?
yes it crash at exacetly that point.plzz help.
may i use MFC DLL in managed code if yes then how?
can u provide example related to that?
|
|
|
|
|
I am trying to get my C program to open and close another application.
ShellExecute (NULL,"open","C:/myproject.exe",NULL,NULL,SW_RESTORE);
works to open the application, but I can't get it to close. I've tried
DestroyWindow("C:/myproject.exe");
but it doesn't work. Can anyone tell me what to use for the file reference for DestroyWindow?
Or is there a completely different way to do this better?
squeaky
|
|
|
|
|
Hi squeaky
Read my article below :-
http://www.codeproject.com/system/newbiespawn.asp
That'll show you how to use CreateProcess which gives you both the process handle and the thread handle for the main thread. Now use EnumWindows to enumerate all top level windows. Call GetWindowThreadProcessId on each HWND and compare with the thread ID you had saved earlier. If they match, post a WM_CLOSE message to this HWND.
Hope this helps,
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Review by Shog9
Click here for review[NW]
|
|
|
|
|
i want to have process main window window hwnd ?
i tried it by its property
Process.MainWindowHwnd
but i could not successed because when i type cast it into hwnd like this
hwnd=(HWND)INTPTR_OB.ToInt64();
then i want to have its child hwnd by using Getwindow.
but when i use that function in order to get child window it return null although it have child hwnd.
why null?
whats the mistake?
r00d0034@yahoo.com
|
|
|
|
|
how to use SetWindowsHookEx in managed code because when i use it in managed code an exception occure at SetWindowsHookEx?
r00d0034@yahoo.com
|
|
|
|
|
I have a dll where i write
// RMLib1.h
#pragma once
#using <mscorlib.dll>
#using <system.runtime.remoting.dll>
using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Channels::Tcp;
namespace RMLib1
{
public __gc class HelloObj:public MarshalByRefObject
{
public:
HelloObj();
String* Greet(String* name);
private:
int numGreet;
};
}
#include "stdafx.h"
this is implementation of these methods
#include "RMLib1.h"
using namespace RMLib1;
HelloObj::HelloObj()
{
Console::WriteLine("HelloObj Activated ");
}
String* HelloObj::Greet(String* name)
{
numGreet++;
String* greeting =S"Hello" ;
return greeting;
}
Inother project i try register this objas remote services
using namespace System;
#using <system.runtime.remoting.dll>
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Channels::Tcp;
#using <rmlib1.dll>
using namespace RMLib1;
// This is the entry point for this application
int _tmain(void)
{
Console::WriteLine(S"Hello World");
TcpChannel* chan = new TcpChannel(8085);
ChannelServices::RegisterChannel(chan);
Console::WriteLine(S"Registering Hello Obj As SingleTon ");
RemotingConfiguration::RegisterWellKnownServiceType(Type::GetType("HelloObj"),"HelloObj",WellKnownObjectMode::Singleton);
Console::WriteLine(S"Waiting For Remote Calls");
Console::WriteLine(S"Hit Enter To Exit ");
Console::ReadLine();
return 0;
}
I can compile this code but when try to excecute it gives me
error
System.ArgumentNullException:Value Can not be Be NULL Parameter Name:Type
This line is giving Problem Any Idea.............
RemotingConfiguration::RegisterWellKnownServiceType(Type::GetType("HelloObj"),"HelloObj",WellKnownObjectMode::Singleton);
|
|
|
|