We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,263 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Issue with program to automate excel in C++

Dear C++ Gurus/Experts,

I am writing a program to automate excel.My program is working well when I use integer (Write/Read) in excel.My program also

works well when I use string.But the issue appears when I use array of strings.I am getting the issue as below
"error C2664: 'SysAllocString' : cannot convert parameter 1 from 'char *' to 'const OLECHAR *' ". Please Help.

//working good with strings

 for(int i=1; i<=15; i++) {
      for(int j=1; j<=15; j++) {
         // Create entry value for (i,j)
          BSTR b;
          VARIANT parm1;
          b = SysAllocString(L"Haroon"); // this line working good
          parm1.vt = VT_BSTR;
          parm1.bstrVal = b;
         // Add to safearray...
         long indices[] = {i,j};
         SafeArrayPutElement(arr.parray, indices, &parm1);
      }
   }

//Having problems with Array of strings

//Array of strings

char *hrs[]={"noor","riz","vignesh"};

 for(int i=1; i<=15; i++) {
      for(int j=1; j<=15; j++) {
         // Create entry value for (i,j)
          BSTR b;
          VARIANT parm1;
          b = SysAllocString(hrs[0]); // issue in this line
          parm1.vt = VT_BSTR;
          parm1.bstrVal = b;
         // Add to safearray...
         long indices[] = {i,j};
         SafeArrayPutElement(arr.parray, indices, &parm1);
      }
   }
2
Contributors
1
Reply
2 Hours
Discussion Span
8 Months Ago
Last Updated
2
Views
haroonrulz
Newbie Poster
3 posts since Aug 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

You need to call SysAllocStringByLen because the strings are char* instead of wchar_t*

Ancient Dragon
Achieved Level 70
Team Colleague
32,142 posts since Aug 2005
Reputation Points: 5,836
Solved Threads: 2,577
Skill Endorsements: 69

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0564 seconds using 2.65MB