Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » char* with "\0" between each char (Char* returned from OLE VARIANT is weird)
char* with "\0" between each char [message #50876] Fri, 11 January 2019 13:56 Go to next message
Xemuth is currently offline  Xemuth
Messages: 20
Registered: August 2018
Location: France
Promising Member
Hello there !

First of all, I wish you all a happy new year !
Today I'm trying to take control of Excel via OLE I did this code :
char* MyExcel::TestingNameOfSheet(){
	
	VARIANT AppResult={0};
	VARIANT AtmSheet={0};
	
	VariantInit(&AppResult);
	VariantInit(&AtmSheet);
	VariantClear(&lgVariant);
	
	lgVariant.vt = VT_I4;
	lgVariant.lVal = 2;	
	
	AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD, &AppResult,xlApp.pdispVal, L"Worksheets", 1, lgVariant);
	AutoWrap(DISPATCH_PROPERTYGET, &AtmSheet, AppResult.pdispVal, L"Name", 0);
	
	return AtmSheet.pcVal;
}

Somewhere else in my code I did this :
...
test = excel.TestingNameOfSheet();
	Cout() << "------------Begin-------------" << "\n";
		if(test !=0){
		do{
			Cout() << (int)*test << "\n";
		}while(++test);
	}
	Cout() << "\n------------Leave-------------" << "\n";
...

this code put into test the name of sheet2 from excel. in my case ("Feuil2").
problem is, when I read it with my "do while" I only get "F" because test is equal to "F\0e\0u\0i\0l\02\0\0\0\0\0 ...".
Can someone explain me why test looks like that ? is it normal ? Or did I make something like classic OLE error ?

Thanks in advance

Best Regard
Re: char* with "\0" between each char [message #50894 is a reply to message #50876] Sun, 13 January 2019 00:19 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 2914
Registered: August 2008
Veteran
Hello Xemuth

I am not able to answer you know. However you may check Bazaar/OfficeAutomation_demo_console that uses Bazaar/OfficeAutomation package to handle Excel and Word files.


Best regards
Koldo
Re: char* with "\0" between each char [message #50923 is a reply to message #50876] Mon, 14 January 2019 12:14 Go to previous messageGo to next message
Xemuth is currently offline  Xemuth
Messages: 20
Registered: August 2018
Location: France
Promising Member
Hello Koldo,

Thanks for your response,
I still has check Bazaar/OfficeAutomation_demo_console and the code looks really more complicated than mine.
I think I did something wrong ^^'

Have a nice day
Re: char* with "\0" between each char [message #50985 is a reply to message #50876] Wed, 16 January 2019 09:17 Go to previous message
Xemuth is currently offline  Xemuth
Messages: 20
Registered: August 2018
Location: France
Promising Member
Hello Again,

I have resolved my problem, the char * I tried to read was a bstr.
To make it readable as normal char * it need to be cast to ASCII char * via this kind of func :

void BSTRtoASC (BSTR str,char * resultat){
	if ( str != NULL ) {
		unsigned long length = WideCharToMultiByte (CP_ACP,0, str,SysStringLen(str), NULL, 0,NULL, NULL	);
		length = WideCharToMultiByte (CP_ACP,0, str,SysStringLen(str), resultat, length,NULL, NULL	);
		resultat[length] = '\0';
	}
}



Have a good day

[Updated on: Wed, 16 January 2019 11:04]

Report message to a moderator

Previous Topic: Help needed to compile windows service example code
Next Topic: New system of feature requests on our forums- please read and use!
Goto Forum:
  


Current Time: Sun Jan 20 17:06:17 CET 2019

Total time taken to generate the page: 0.00642 seconds