Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am new for VC++.I am trying to change MFCDLL file for my Project.My Task is Multiple Port access.that means user accesses Multiple Port at same time.The below code is "Port On/Off" Function.
Old Code
C++
extern "C" __declspec(dllexport) void PortExit(int val)
{
	m_exitflag=val;
}
it is working on One - One Relationship that menas if i connect one COM Port .It is ok.But when i connect multiple port it is not worked.So i changed my code like this.
New Code
extern "C" __declspec(dllexport) void PortExit(int val,char *Ports)
{
	m_exitflag=val;
       port=Ports;
}

here,Port means get Port No.But it is not working.Why?I got this error message when i access this Dll in my Project .it is in C#.net
Message    : Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Stack Trace:    at Testing.MultiplePrint.PortExit(Int32 ExitValue, String port)

Here MultiplePrint is Usercontrol .it develops in C#.net.
So Please Tell me.How to solve this issue .It is very urgent.
Posted
Updated 27-Jul-11 21:13pm
v4

Does your port variable is a null terminated string or a single char. If it is a single char, then on C# side, it should probably be a byte.
 
Share this answer
 
v2
Comments
naraayanan 29-Jul-11 0:03am    
Thanks for reply.It is a String.So I used in my C#.net Project as a String.I set a value of Port number in this char *Ports in the PortExit.
Philippe Mori 29-Jul-11 7:50am    
Then if it is a string.... you probably have to tell C# what kind on string is is. In that case, I think it is an ANSI string (single byte) and by default C# probably assume Unicode (two bytes).
naraayanan 31-Jul-11 23:34pm    
Thanks Philippe
In your C# project declare the PortExit signature like this,

C#
PortExit(Int32 ExitValue, out string port)
{
....
}


I guess this will solve your problem.
 
Share this answer
 
Comments
naraayanan 28-Jul-11 4:14am    
Thanks for your reply .. But I got this error
Error 5 The best overloaded method match for 'Testing.MultiplePrint.SetExit(int, out string)' has some invalid arguments E:\Testing\Testing\Testing\Testing\MultiplePrint.cs 73 20 Testing
What will i do?
Richard MacCutchan 28-Jul-11 5:28am    
Well the message is quite clear, your SetExit() call on line 73 is incorrect. If you really do not understand this message you should go back to your C# documentation at the section on overloaded methods.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900