CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2012
    Posts
    19

    Issue with program to automate excel

    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.

    Program:

    //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. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Issue with program to automate excel

    Just use UNICODE strings in the array the same way you do it for a single string:
    instead of
    Quote Originally Posted by haroonrulz
    Code:
    char *hrs[]={"noor","riz","vignesh"};
    use
    Code:
    wchar_t *hrs[]={L"noor", L"riz", L"vignesh"};
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured