|
Thanks alot for your answer ,I wrote my code same as you mentioned ,my code is :
Header:
extern "C" __declspec(dllexport) HRESULT __stdcall DllRegisterServer(void);
CPP:
HRESULT __stdcall DllRegisterServer(void)
{
}
but when I compile and build it I get this error:
error C2375: 'DllRegisterServer' : redefinition; different linkage
I don't know what is its reason.
I'm appreciated for your help.
Best Regards.
Orchid
|
|
|
|
|
Based on:
http://msdn2.microsoft.com/en-US/library/5k6kw95a.aspx[^]
You will get this error if the prototype is defined twice with different linkage...
In otherword, some already defines DllRegissterServer(void) before you header definition...
To find it, you could add the compiler switch /P to the CPP including the header file. Then, right-click on the file and select 'compile'. This will output a file to disk that has all the included file and the line numbers... You can then search it for DllRegisterServer and figure out where it's coming from.
Remember to remove the /P switch before building your project.
I'm not sure what type of MFC dll you're using - but the other definition is coming from MFC most likely...
gmileka
|
|
|
|
|
I'm curious how the MFC dll was created through the Wizard... and which VS is being used. Since this is a C++/CLI forum, I would expect some interaction between the 'managed' MFC stuff and your declaration.
gmileka
|
|
|
|
|
I am attempting to write to a special serial device that requires one I/O to be sent for both reads and writes. The device receives a packet of information, like what would be sent on a WriteFile, and then expects to fill in a packet of data and return it like ReadFile.
Neither readfile or writefile will work, since write only sends packets and reads only retrieve them. The device will not operate with two IOs, as in a writefile/readfile sequence.
Does anyone know of an API call I can make to accomplish this? DeviceIOControl allows for both input and output packets, but I cannot find an IOCTL that implies it will do this.
Any help would be appreciated.
Thanks
Bill
|
|
|
|
|
What excatly u meant by "The device will not operate with two IOs"?
As long you opened the port and u have a valid handle to the port, you can write into it using WriteFile and read from using ReadFile.
Call WriteFile by passing the packet record expected by the device to OUT to the device.
Then Keep polling the port for an IN using ReadFile until u get the input or a predefined timeout expires.
Or else you can put a Sleep(100) immediatly after WriteFile and then try ReadFile.
Generally this is how RS232 works.
cheers...milton.
|
|
|
|
|
I have the following code, and I want to pass the variable test1 into the form, so that the form can read my test1 value. The var will be passed to SetParameter, a method under Form1. But I've encounted the following problem:
error C2664: 'void System::Windows::Forms::TextBox::set_Text(System::String __gc *)' : cannot convert parameter 1 from 'int' to 'System::String __gc *'
error C2039: 'SetParameter' : is not a member of 'System::Windows::Forms::Form'
Form1.cpp main:
int APIENTRY _tWinMain(HINSTANCE hInstance,<br />
HINSTANCE hPrevInstance,<br />
LPTSTR lpCmdLine,<br />
int nCmdShow)<br />
{<br />
int test1;<br />
string line;<br />
System::Threading::Thread::CurrentThread->ApartmentState = System::Threading::ApartmentState::STA;<br />
ifstream iFile("test.txt");<br />
<br />
if (!iFile)<br />
{<br />
return -1;<br />
}<br />
<br />
iFile >> test1;<br />
<br />
iFile.close();<br />
<br />
Form *Form1 = new Form();<br />
<br />
Form1->SetParameter(test1);
<br />
Application::Run(Form1);
return 0;<br />
}
Form1.h:
public __gc class Form1 : public System::Windows::Forms::Form<br />
{ <br />
public:<br />
Form1()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
void SetParameter(int t){<br />
textBox1->Text = t;<br />
}<br />
<br />
protected:<br />
void Dispose(Boolean disposing)......<br />
.....<br />
.....<br />
.....
Actually I dunno where should I put the SetParameter, and how to convert int "t" to __gc textbox text as shown in the method.(since compiling the method results the first error)
Million thanks again.
|
|
|
|
|
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 ?
|
|
|
|