The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Passing String Variables to OC functions
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

bg-phys

USA
Posts

Posted - 08/10/2006 :  4:50:48 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version: 7.5 SR5
Operating System: Win XP SP2

I'd like to pass a string as an argument from a Labtalk script to an OC function. Is that possible? I've been getting an error with the following setup:

Inside a *.ogs file:

[LTCode]
type -b "Choose data file.";
getfile *.dat; //Stores filename to %A, file path (with trailing \) to %B
cFunction(%B%A);
type -a %A;



Inside a *.c file:


int cFunction(char * input)
{
printf("Input is %s\n\n",input);
return 0;
}



When I try to run by typing cFunction("Hello") in the script Window I get a Command Error.

When I try to run it by clicking a toolbar button that's set to run the [LTCode] section, I get no output to the Script Window.

In fact, I can't get output to the script window even if the OC Function is just a Hello World function and has no input parameters.

Is it possible to pass string variables to OC functions from LabTalk? If it isn't possible, how to I access the Labtalk string variables that I want the OC function to know about?

Is it possible to ensure that printf output from OC functions goes to the script window even when the OC function is started from a button that runs a labtalk script? (which in turn calls the OC function) If not, how do I view printf output from OC functions? (I still would like to call the function with a toolbar button.)


BG

P.S. I feel like some of my questions were a bit confusing. Please ask me to reword them if necessary.


easwar

USA
1965 Posts

Posted - 08/10/2006 :  5:00:29 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi BG,

Change your OC function to:
int cFunction(string input)
{
printf("Input is %s\n\n",input);
// or use out_str() function such as:
out_str(input);
return 0;
}

When calling the function from LT, note that if you have spaces in your string, you either need to protect using paranthesis or quote the string, such as:
cFunction(blah blah); // no quotes required in this case
cFunction "blah blah"

Also note that there are functions such as LT_get_str and LT_set_str that can be used to get and put strings between OC and LT.

As for making sure that the script window opens, you can issue the following statement in your LT script code:
type -a;
or you can issue that statemente from OC code if necessary using
LT_execute("type -a;");

Easwar
OriginLab



Edited by - easwar on 08/10/2006 5:03:20 PM
Go to Top of Page

bg-phys

USA
Posts

Posted - 08/10/2006 :  5:49:13 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
That works perfectly. All I had to do was change the input type from char* to string. Thanks for the quick reply.

Quick question though:

Does fopen(filename,"rb"); still work if filename is a string instead of a char*?


Edited by - bg-phys on 08/10/2006 5:54:08 PM
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 08/10/2006 :  6:35:52 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Does fopen(filename,"rb"); still work if filename is a string instead of a char*?


string class in Origin C is similar to MFC CString, so char* cast is automatic. So yes, you can put string into any function that expect LPCSTR or char*


CP


Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000