Click here to Skip to main content
15,891,136 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
QuestionRe: difficulty coming up with the right format. Pin
Mark Salsbery23-Jul-09 5:56
Mark Salsbery23-Jul-09 5:56 
AnswerRe: difficulty coming up with the right format. Pin
Member 315372123-Jul-09 7:49
Member 315372123-Jul-09 7:49 
AnswerRe: difficulty coming up with the right format. Pin
amatecki25-Jul-09 9:17
professionalamatecki25-Jul-09 9:17 
QuestionTo write in Status bar Pin
mikobi22-Jul-09 2:45
mikobi22-Jul-09 2:45 
AnswerRe: To write in Status bar Pin
led mike22-Jul-09 4:25
led mike22-Jul-09 4:25 
Questiondepth first search help.. Pin
neha_rai21-Jul-09 10:34
neha_rai21-Jul-09 10:34 
AnswerRe: depth first search help.. Pin
Adam Roderick J23-Jul-09 0:24
Adam Roderick J23-Jul-09 0:24 
QuestionHow to pass a pointer of data to the managed side on a C++ wrapper Pin
sinosoidal19-Jul-09 23:55
sinosoidal19-Jul-09 23:55 
Hi,

I'm doing a simple managed C++ class to grab data from a USB device and pass it to the C# side.

This is my class:

public __gc class Communication<br />
	{<br />
		private:<br />
			LPVOID	dataInBuffer;			<br />
			HANDLE _hFileHandle;<br />
			int		nBytesToRead;			<br />
			int		maxPacketSize;<br />
<br />
		public:<br />
<br />
			Communication()<br />
			{<br />
				_hFileHandle = INVALID_HANDLE_VALUE;<br />
<br />
				maxPacketSize = 256;<br />
				dataInBuffer = malloc(sizeof(char) * maxPacketSize);<br />
				nBytesToRead = maxPacketSize;<br />
			}<br />
<br />
			~Communication()<br />
			{<br />
				if( _hFileHandle != INVALID_HANDLE_VALUE )<br />
				{<br />
					CloseHandle( _hFileHandle );<br />
				}<br />
			}<br />
<br />
			bool OpenDevice( String* driverName )<br />
			{<br />
				char* lpFileName = new char[driverName->Length + 10];<br />
				<br />
				sprintf( lpFileName, "\\\\?\\%s", driverName );<br />
				<br />
				_hFileHandle = CreateFile((LPCSTR) lpFileName,GENERIC_READ,0,0,OPEN_EXISTING,0,0);<br />
<br />
				if( _hFileHandle == INVALID_HANDLE_VALUE )<br />
				{<br />
					puts("Couldn't not open device");<br />
				}<br />
<br />
				delete lpFileName;<br />
<br />
				return( _hFileHandle != INVALID_HANDLE_VALUE );<br />
			}<br />
<br />
			BOOL CloseDevice()<br />
			{<br />
				return CloseHandle( _hFileHandle );<br />
			}<br />
<br />
			int GetPacket()<br />
			{<br />
				char outBuffer[256];<br />
<br />
				int nBytesRead = -1;<br />
<br />
				if (_hFileHandle!=INVALID_HANDLE_VALUE)<br />
				{<br />
					ReadFile(_hFileHandle, dataInBuffer, nBytesToRead, (PULONG) &nBytesRead,0);<br />
				}<br />
<br />
				memset(outBuffer,0,maxPacketSize*sizeof(char));<br />
				memcpy(outBuffer,dataInBuffer,maxPacketSize*sizeof(char));<br />
<br />
				return nBytesRead;<br />
			}<br />
	};


My problem right now it how to pass the outBuffer variable in the GetPacket method outside the class.

If I let the variable being declared inside the function, it gets erase when the function ends and my data goes with it.

If I declare that variable in the class itself, the compiler says the following:

'outBuffer' : must explicitly specify __gc or __nogc for an array declared in a managed type

And if I put the __gc attribute on the variable, then the compiler tells the following:

'identifier' : '__gc' can only be applied to a class, struct, interface, array or pointer

So... what do I have to do in order to make this variable available in the C# side?

I'm using char, because I need a signed 8-bit value on each position of the array.

Can anyone give me some lights here?

Thanks,

Nuno
AnswerRe: How to pass a pointer of data to the managed side on a C++ wrapper Pin
N a v a n e e t h20-Jul-09 15:25
N a v a n e e t h20-Jul-09 15:25 
AnswerRe: How to pass a pointer of data to the managed side on a C++ wrapper Pin
amatecki23-Jul-09 8:39
professionalamatecki23-Jul-09 8:39 
QuestionRegarding IWshRuntimeLibrary::IFileSystem Pin
V K 219-Jul-09 22:43
V K 219-Jul-09 22:43 
AnswerRe: Regarding IWshRuntimeLibrary::IFileSystem Pin
lakshman rao13-Jun-20 3:58
lakshman rao13-Jun-20 3:58 
GeneralRe: Regarding IWshRuntimeLibrary::IFileSystem Pin
Richard MacCutchan13-Jun-20 6:28
mveRichard MacCutchan13-Jun-20 6:28 
Questionneed help with "System.Runtime.InteropServices.SEHException" error Pin
UserNameless14-Jul-09 19:36
UserNameless14-Jul-09 19:36 
AnswerRe: need help with "System.Runtime.InteropServices.SEHException" error Pin
Richard Andrew x6414-Jul-09 20:36
professionalRichard Andrew x6414-Jul-09 20:36 
GeneralRe: need help with "System.Runtime.InteropServices.SEHException" error Pin
UserNameless14-Jul-09 20:57
UserNameless14-Jul-09 20:57 
GeneralRe: need help with "System.Runtime.InteropServices.SEHException" error Pin
Richard Andrew x6414-Jul-09 21:22
professionalRichard Andrew x6414-Jul-09 21:22 
GeneralRe: need help with "System.Runtime.InteropServices.SEHException" error Pin
UserNameless14-Jul-09 21:26
UserNameless14-Jul-09 21:26 
GeneralRe: need help with "System.Runtime.InteropServices.SEHException" error Pin
Richard Andrew x6414-Jul-09 21:35
professionalRichard Andrew x6414-Jul-09 21:35 
GeneralRe: need help with "System.Runtime.InteropServices.SEHException" error Pin
UserNameless14-Jul-09 21:44
UserNameless14-Jul-09 21:44 
QuestionC++/CLI being used with VB and VC++ Pin
Shadowsoal14-Jul-09 8:45
Shadowsoal14-Jul-09 8:45 
AnswerRe: C++/CLI being used with VB and VC++ Pin
N a v a n e e t h14-Jul-09 16:12
N a v a n e e t h14-Jul-09 16:12 
GeneralRe: C++/CLI being used with VB and VC++ Pin
Shadowsoal15-Jul-09 4:13
Shadowsoal15-Jul-09 4:13 
GeneralRe: C++/CLI being used with VB and VC++ Pin
Shadowsoal15-Jul-09 5:21
Shadowsoal15-Jul-09 5:21 
GeneralRe: C++/CLI being used with VB and VC++ Pin
N a v a n e e t h15-Jul-09 17:49
N a v a n e e t h15-Jul-09 17:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.