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

Managed C++/CLI

 
Generalamazon upload need help... Pin
Sumit Kapoor19-May-04 19:57
Sumit Kapoor19-May-04 19:57 
QuestionHow to detect keyboard Pin
Ajay_Saraf19-May-04 19:12
Ajay_Saraf19-May-04 19:12 
GeneralC++ Compilers Pin
DarkExploi^19-May-04 12:35
sussDarkExploi^19-May-04 12:35 
GeneralRe: C++ Compilers Pin
ian mariano20-May-04 9:43
ian mariano20-May-04 9:43 
GeneralRe: C++ Compilers Pin
Member 62566624-May-04 9:48
Member 62566624-May-04 9:48 
Generali need to get the chat text of msm messanger Pin
Member 96792618-May-04 9:02
Member 96792618-May-04 9:02 
QuestionHow to get an Array allocated in Unmanamed code Pin
hasansheik18-May-04 3:43
hasansheik18-May-04 3:43 
AnswerRe: How to get an Array allocated in Unmanamed code Pin
Member 93002221-May-04 18:58
Member 93002221-May-04 18:58 
There are two ways you can call ReadFile:
First way:
import the function:
[DllImport(S"Kernel32.dll", EntryPoint="ReadFile", CharSet=CharSet::Auto)]<br />
	extern "C"  Boolean ReadFileNative(IntPtr hFile,StringBuilder *lpBuffer,<br />
	UInt32 nNumberOfBytesToRead,<br />
	UInt32 *lpNumberOfBytesRead, <br />
	Int32);

Here's a function that returns text from a file:
String *GetFileTextWithImport(String *fileName){<br />
		FileStream *fs=new FileStream(fileName,FileMode::Open);<br />
	//Wrapping a handle with HandleRef guarantees that<br />
		//the managed object is not garbage collected <br />
		//until the platform invoke call completes.<br />
		HandleRef hRef=HandleRef(fs,fs->Handle);<br />
		StringBuilder *sbText=new StringBuilder(fs->Length);<br />
		UInt32 uiToRead=0;<br />
		ReadFileNative(hRef.Handle,sbText,fs->Length,&uiToRead,0);<br />
		fs->Dispose();<br />
		return sbText->ToString();<br />
	}

Second Way:
just call ReadFile without importing
String *GetFileText(String *fileName){<br />
		FileStream *fs=new FileStream(fileName,FileMode::Open);<br />
		HandleRef hRef=HandleRef(fs,fs->Handle);<br />
		IntPtr ptrText=Marshal::AllocHGlobal(fs->Length);<br />
		DWORD uiToRead=fs->Length, uiRead=0;<br />
		ReadFile((HANDLE)hRef.Handle,ptrText.ToPointer(),uiToRead,&uiRead,NULL);<br />
		String *strRet=Marshal::PtrToStringAnsi(ptrText);<br />
		Marshal::FreeHGlobal(ptrText);<br />
		fs->Dispose();<br />
		return strRet;

P.S. By the way, why not use the System.IO.StreamReader?
GeneralRe: How to get an Array allocated in Unmanamed code Pin
hasansheik21-May-04 20:06
hasansheik21-May-04 20:06 
GeneralRe: How to get an Array allocated in Unmanamed code Pin
Member 93002222-May-04 7:33
Member 93002222-May-04 7:33 
GeneralJava Bean Pin
selvi_saru18-May-04 1:43
selvi_saru18-May-04 1:43 
GeneralRe: Java Bean Pin
Curi0us_George27-May-04 19:29
Curi0us_George27-May-04 19:29 
QuestionErrors? Pin
Gra3y17-May-04 23:31
Gra3y17-May-04 23:31 
GeneralManaged C++ and VCF Pin
Jim Crafton17-May-04 8:38
Jim Crafton17-May-04 8:38 
GeneralRe: Managed C++ and VCF Pin
Isaac_Roh17-May-04 15:22
Isaac_Roh17-May-04 15:22 
GeneralDirect input from a key Pin
zaXch17-May-04 3:33
zaXch17-May-04 3:33 
GeneralRe: Direct input from a key Pin
RNEELY17-May-04 5:54
RNEELY17-May-04 5:54 
GeneralCode editor for Assembly, C and C++ Pin
Mekong River16-May-04 14:59
Mekong River16-May-04 14:59 
GeneralRe: Code editor for Assembly, C and C++ Pin
psmkb111024-May-04 21:58
psmkb111024-May-04 21:58 
GeneralRe: Code editor for Assembly, C and C++ Pin
Mekong River1-Jun-04 5:42
Mekong River1-Jun-04 5:42 
GeneralReturning a Pointer to a array... Pin
Axiverse14-May-04 18:31
Axiverse14-May-04 18:31 
QuestionHow do I get my pc to support php? Pin
Streetproject14-May-04 10:03
Streetproject14-May-04 10:03 
AnswerRe: How do I get my pc to support php? Pin
Member 122629419-May-04 3:18
Member 122629419-May-04 3:18 
GeneralString Parsing ! Pin
ra_sasi14-May-04 6:23
ra_sasi14-May-04 6:23 
Generalemail for large attachements Pin
ramki_14-May-04 5:50
ramki_14-May-04 5:50 

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.