|
You need to convert the 'int i' to a C string. You could use itoa() or printf(). Make sure the buffer is large enough to hold the resulting string.
Once you have a C string, convert it to a 'System::String'. You don't need to convert it to __gc textbox because you're assigning it to the 'Text' property of the text box... The property expects a string.
gmileka
|
|
|
|
|
hello
everythings gos good with the code Below, but when i try to make object (MessageQueue TheQueue = new MessageQueue;), it give me an errors says :
Error 1 error C3821: 'System::Messaging::MessageQueue': managed type or function cannot be used in an unmanaged function c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26
Error 2 error C3624: 'System::ComponentModel::Component': use of this type requires a reference to assembly 'System' c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26
Error 3 error C3821: 'System::Messaging::MessageQueue': managed type or function cannot be used in an unmanaged function c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26
Error 4 error C2750: 'System::Messaging::MessageQueue' : cannot use 'new' on the reference type; use 'gcnew' instead c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26
Error 5 error C3642: 'System::Messaging::MessageQueue::MessageQueue(void)' : cannot call a function with __clrcall calling convention from native code c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26
Error 6 error C3175: 'System::Messaging::MessageQueue::MessageQueue' : cannot call a method of a managed type from unmanaged function 'SendToQueue' c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26
Error 7 error C2664: 'System::Messaging::MessageQueue::MessageQueue(System::String ^)' : cannot convert parameter 1 from 'System::Messaging::MessageQueue *' to 'System::String ^' c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26
------------------------------------------------------
------------------------------------------------------
<br />
#include "stdafx.h"<br />
#using <system.messaging.dll><br />
using namespace System::Messaging;<br />
<br />
#ifdef _MANAGED<br />
#pragma managed(push, off)<br />
#endif<br />
<br />
BOOL APIENTRY DllMain( HMODULE hModule,<br />
DWORD ul_reason_for_call,<br />
LPVOID lpReserved<br />
)<br />
{<br />
return TRUE;<br />
}<br />
<br />
int _stdcall Sum(int inA, int inB) {<br />
return (inA + inB);<br />
}<br />
<br />
int _stdcall SendToQueue(char * SBody,char * SLabel)<br />
{<br />
MessageQueue TheQueue = new MessageQueue;<br />
return 0;<br />
}<br />
<br />
#ifdef _MANAGED<br />
#pragma managed(pop)<br />
#endif<br />
|
|
|
|
|
Here agin u chose an an unmanged project type insted of a managed one. Hope my reply to ur post below will make things clear.
rgds...milton
|
|
|
|
|
You've told the compiler that SendToQueue() is unmanaged, yet you're trying to use managed code in it.
And it should be
MessageQueue^ theQueue = gcnew MessageQueue;
--Mike--
Visual C++ MVP
LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
nothing changes still have errors when i place MessageQueue^ theQueue = gcnew MessageQueue;
inside my function SendToQueue()
|
|
|
|
|
|
Yes, exactly .. he was trying to call managed code from unmanaged function. He got fixed creating a new managed cpp project.
rgds...milton
|
|
|
|
|
ALQallaf wrote: MessageQueue TheQueue = new MessageQueue;
As Mike said, you need to use gcnew and not new . Alternatively you can use stack semantics.
MessageQueue TheQueue;
TheQueue.Func(...);
Regards,
Nish
|
|
|
|
|
i tryed your syntax , but still having an errors nothing changed
|
|
|
|
|
ALQallaf wrote: i tryed your syntax , but still having an errors nothing changed
Check the following :
- Are you using the old syntax? You cannot use C++/CLI with the old syntax mode.
- Have you included references to all required assemblies?
- Are you inside a #pragma unmanaged block? If so, you cannot (obviously) do managed stuff in there.
Regards,
Nish
|
|
|
|
|
Thanks Nishant Sivakumar its works now
|
|
|
|
|
Nish he was trying to call managed dll from an unmanged win32 dll. thats why the err.
rgds..milton.
|
|
|
|
|
Hello
im working with MSMQ , so i want to make dll that will send to MSMQ,
so how can i include MSMQ Library (System.Messaging.dll) in VC++ ?
C:\WINNT\Microsoft.NET\Framework\v2.0.50727\System.Messaging.dll
thanks
|
|
|
|
|
you can use #using directive to include the managed dlls into your code.
Then use the namespace declaration and create the class instance. See the sample below.
#using <system.messaging.dll><br />
using namespace System::Messaging;<br />
<br />
if ( !MessageQueue::Exists( queuePath ) )<br />
MessageQueue::Create( queuePath );<br />
cheers..milton
|
|
|
|
|
thank you
i tryed it but it give me this error:
Error 1 fatal error C1190: managed targeted code requires a '/clr' option
can you know how to resolve it ?
|
|
|
|
|
Project Properties -> configuration Properties -> General -> Common Language runtime support
set-->Common Language Runtime Support (/clr)
but also it gives me this error:
Error 1 Command line error D8016 : '/MTd' and '/clr' command-line options are incompatible cl
how can i fix it please ?
|
|
|
|
|
Error 1 Command line error D8016 : '/MTd' and '/clr' command-line options are incompatible
'/MTD' is the Multithreded C Runtime debug version. That means you chose an unmanaged project type. What kind of project you are working on ?
If you need to call .net libaries from an unmanaged type, best way is to wrap all ur bussiness rules into an assembly and use CCW - Com callable wrapper to invoke the wrapper .net component from ur unmanaged app.
Or else change the project type to a managed.
rgds...milton.
|
|
|
|
|
actually i created my project with VC6++, the Convert and open project with VC2005, emm ok i will try to open new fresh project from 2005 directly , so i have to open managed dll project from vc2005.
can you tell me which option when i want to create project give me managed dll ? currently i make win32 project--->dll with puting sign on Export symbols only.
is im in right way ?
-- modified at 17:42 Saturday 6th May, 2006
|
|
|
|
|
i think yes im in safe side ,
now i can compile with no errors after set Common Language Runtime Support (/clr), i want to know if there is any changes between dll on vc6++ and vc2005,
everytime i call function within dll by using this declaration
int _stdcall SendToQueue(char * SBody,char * SLabel)
{
return 123;
}
and i have to make .def file and write exported function header inside it
so it will work with vc2005 or there is problem with it ?
|
|
|
|
|
You were in the wrong side.
you again choose an unmanaged project type because win32 project is an unmanged type.
After all what you need is to call MSMQ APIs right? You can do it in two ways:
1) Either use unmanaged MSMQ Apis
2) Or use Managed .Net class libraries, which is the one you chose.
For the first option:
you can go for an unmanaged project type. ie it can be a vc++6 project or a VC++8 MFC application.
Then for accessing the MSMQ apis go thru http://www.thecodeproject.com/w2k/msmq.asp.
This method will be fater as MSMQ apis are unmanged and you are directly dealing with the apis.
Second option is to use managed dlls:
This is the option you chose, by using System.Messaging.dll. This is not that good as the previous one as it wrapes the actual MSMQ COM Apis under the hood.
If you want to go for this option yu can do it in the following ways:
a)Use an Unmanaged VC++ app and use interop for calling the wrapper u created on managed
System.Messaging.dll. For this you have to create one managed wrapper dll (New project -->
Visual C++ -->CLR --> Class library) and wrap all your msmq requirements using
System.Messaging.dll functions.Then use COM iterop to use this managed wrapper dll from ur
Unmanaged VC++8 application.
(Or you can avoid wrapper dll by using CorBindToRuntimeEx(), but more complicated. better dont
go for this if u r beginner).
b)USe a Managed VC++ application (New project --> Visual C++ -->CLR --> Windows forms applicaion /
Class library). This is a c++/cli application.
This will be the easiest methed if you are planning to use System.Messaging.dll (in C++) instaed
of the MSMQ COM apis.
Or another choice is, you really want to go for vc++? if you go for C# and System.Messaging.dll then it will be the easiest of all.
more questions are welcome ...milton
|
|
|
|
|
i think it works with option :
b)USe a Managed VC++ application (New project --> Visual C++ -->CLR --> Windows forms applicaion /
Class library). This is a c++/cli application.
This will be the easiest methed if you are planning to use System.Messaging.dll (in C++) instaed
of the MSMQ COM apis.
--------
Thank you Milton finally its works
|
|
|
|
|
had gone for a short hiking to Wachusett Mountain MA. Just back now. sorry for abt the delay buddy.
Be aware that the option u selected is managed c++ (c++/cli) app and not a typical vc6++ like unmanaged application.
cheers..milton.
|
|
|
|
|
The Microsoft Most Valuable Professional (MVP) Program recognizes and thanks outstanding members of technical communities for their community participation and willingness to help others. The program celebrates the most active community members from around the world who provide invaluable online and offline expertise that enriches the community experience and makes a difference in technical communities featuring Microsoft products.
I've been asked by Microsoft to nominate North American Visual C++ developers deserving of Microsoft MVP status. Please make your nominations here or email me at webmaster@codeproject.com.
cheers,
Chris Maunder
CodeProject.com : C++ MVP
|
|
|
|
|
Chris Maunder wrote: I've been asked by Microsoft to nominate North American Visual C++ developers
i am C++ developper and would be soooo happy to be MS MVP, but i'm not living in North America
do you know why they look for north america developers only ?
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
|
|
|
|
|
They have MVPs all over the world. They are not only looking for North America MVPs.
gmileka
|
|
|
|