View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel.sdk
joel joel is offline
external usenet poster
 
Posts: 9,101
Default Passing a string to excel from a C app

I think your answer lies in this statement

DISPPARAMS dispParams = { NULL, NULL, 0, 0 };

these arre the parements that you can pass. I guessing the first two NULLs
are standard c language paraments arg(0) - program name and arg(1) - the
number of parameters. These are probably being added by the library. The
two 0's are C-Language Null terminated strings. C- Language parameter for
Main are all strings. Each string is terminated with a NULL (zero). So
really all you have to do is replace the 0's with ascii striings. The
C-Language parameter list is just consecutive memory with 0's terminating the
parameters. The arg(0) indicates how many NULL terminated string are going
to occur. You just have to make sure enough memory is allocated to pqass all
the parremters.

"Rob Y" wrote:

I'm trying to add some simple excel automation to my C app. I found
some C++ code that I was able to modify to do what I want, but that code
won't link to my C app, and I can't convert the app to C++ just for this.

I found an article with a tiny 'OLE Automation from a C App' code sample
that works in my app at:
http://support.microsoft.com/kb/181473
but that sample simply starts Excel and sets 'visible'. I need to do a
little (not much) more, passing in file paths and macro names, etc.

Using the C sample as a template, I'm trying to convert the C++ sample
to C. The C sample has code to pass an integer parameter, but I need to
be able to pass in file paths as strings. The C++ sample does this by
converting them to BSTR's (VB string? OLE string?) and passing them as
VT_BSTR. Will Excel accept string parameters as VT_LPSTR, or do I have
to pass them as BSTR's. If so, can anybody provide a code snippet to
create a BSTR from a normal C string?

Thanks,
Rob