i have a header file and one of the function prototypes is

extern "C" LONGBOOL _stdcall LT360LIB_CmdValue(LONGINT Handle, LONGINT CmdID, char * ParamValue);

and there is an example of using this code

z=LT360LIB_CmdValue(0, lt_Goto_CCW, "5.5");

when i try this code it compile and builds correctly but when i run the program , it halts with no error messages ( and the processor goes to 100% as if it went to an infinite loop).

could it be due to passing a string to a character pointer although i had no compiler errors?
Thanks

No.

so its ok to pass a string to a character pointer and ill have to check for other causes , ill see thanks

Well, it does make any difference in assiging the a string to a char pointer. What I really wonder is how is that killing your processor. Is there any loops which goes to an infinite loop? Or there may be some problems with the implemenation of that function may be. What does your application do?

ssharish

im actually controlling a hardware (turntable) ,
actually i just tested this function, i didnt write any other code ,it could be due to something happening in the .dll it calls. But it occured to me maybe this problem is due to not having the device connected to my pc , the function maybe waiting for a feedback from the device, currently the device is not around me i was just testing the codes.ill check again when i connect the device.

by the way one more question, in the documentation they say this header can be used also to return a string in paramValue

//---------------------------------------------------------------------------
//  Function: 	LT360LIB_CmdValue
//  Abstract:   Sends a Command to the LT360
//              Also dislays error message dialog if command fails
//  Parameters: Handle: LT360 Index returned from Link
//              CmdID : Command Identifier
//              ParamValue : Parameter String for Value, may be nil
//                           [B]****Get calls return strings in ParamValue****[/B]
//  Returns:    Returns TRUE if executed successfully
//---------------------------------------------------------------------------
extern "C" LONGBOOL _stdcall LT360LIB_CmdValue(LONGINT Handle, LONGINT CmdID, char * [B]ParamValue[/B]);

by using "lt_GetMoving" instead "lt_Goto_CCW" in the function posted at the beggining. but how can i obtain the string returned in paramvalue, can i just declarea pointer of type e.g char*p, then placing p as the third parameter?

ParamValue must point to a large enough buffer to receive the information. The documentation should provide information wrt 'large enough buffer'.

You might use something like

const int GETMOVING_SIZE 1024;
char paramValue[GETMOVING_SIZE] = {0};

if(LT360LIB_CmdValue(handle, lt_GetMoving, paramValue))
{
    // here you can check the content of paramValue
}

sorry forgot to mention paramvalue is supposed to return (in the lt_GetMoving)
"CCW" or"CW" or "NO"

thanks for the reply, is it possible to check the value of paramvalue after the function call since it is passed by value?

i tried this test code

#include <iostream>
#include <string>
using namespace std;

void test (char *);

void main()
{
const int GETMOVING_SIZE =5;
char paramValue[GETMOVING_SIZE] = {0};
test(paramValue);
cout<<paramValue;

}

void test (char*paramvalue)
{
	paramvalue=new char [5];
	paramvalue="issa";

		
}

but no output came, i think it is due to passing paramvalue by value, which will be same if i tried with the original code since paramvalue is declared as pointer by value(i.e any changes made to paramvalue won't be seen outside the function that used it).
Thanks again

i tried this test code

#include <iostream>
#include <string>
using namespace std;

void test (char *);

void main()
{
const int GETMOVING_SIZE =5;
char paramValue[GETMOVING_SIZE] = {0};
test(paramValue);
cout<<paramValue;

}

void test (char*paramvalue)
{
	paramvalue=new char [5];
	paramvalue="issa";

		
}

but no output came, i think it is due to passing paramvalue by value, which will be same if i tried with the original code since paramvalue is declared as pointer by value(i.e any changes made to paramvalue won't be seen outside the function that used it).
Thanks again

Your test() function is making paramvalue point to something entirely different. That's not the way to go about it.

test() is supposed to expect a buffer passed to it, and it ought to fill the buffer with whatever characters it sees fit. It should look more like:

void test(char *paramvalue) {
	strcpy(paramvalue, "issa");
}

Edit:

In my haste, I overlooked this:

paramvalue=new char [5];
	paramvalue="issa";

That shows you've got the whole idea of pointers, arrays and strings (and probably a few more things that come into play here) totally jumbled up. You should consult a good book.

thanks man i got you , i tried it and it works fine. by the way i messed up big time inthe code above some times i used paramvalue and on other occasions paramValue lol thanks again.

anyway just to make sure when i want to take the returned string from ParamValue,

extern "C" LONGBOOL _stdcall LT360LIB_CmdValue(LONGINT Handle, LONGINT CmdID, char * ParamValue);

i'll have to pass an array of type char to the pointer ParamValue and the data will be passed to the array and can be seen outside the function . i.e ( similar to what mitrmkar said)
thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.