LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how to redefine the function name

I have create a VISA Driver dll files and the driver runs well,but now i
get another difficuty.I Want to redefine the function name.below is what I
have done.

#defien test test6110

then i want that the function such as test6110_Init,test6110_Selt_Test can
be used by test_Init,test_Self_Test.

The thoughts I do this is that when I get many Instruments driver,I can
redefine the

#defien test test6110
i can get test_Init,Test1_Init,etc.

But Now when I did this,there is not an error occured,But the application
that use this driver
got a error," Missing prototype."How to solve this error.

Any information will get my thanks:) thank you
0 Kudos
Message 1 of 4
(3,335 Views)
#define statement define constants. Constants cannot be used in the names of symbols (variable, functions, etc.) What you could do is define a compile flag like COMPILEMODE and use it to define a different set of functions if it's defined. Most C libraries do this to include/remove functions based on OS and project settings.

Best Regards,

Chris Matthews
Measurement Studio Support Manager
0 Kudos
Message 2 of 4
(3,335 Views)
I may have missed your point here, but if all you want to do is rename the function internally, then you can define it as shown below:
------------------
#include
#include


// Function Declaration

int OldFuncName (int param1, int param2);

#define NewFuncName (OldFuncName)



int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow)
{

int i;

if (InitCVIRTE (hInstance, 0, 0) == 0)
return -1; /* out of memory */

i = OldFuncName (1,2);

printf ("%d\n",i);

i = NewFuncName(2,3);

printf ("%d\n",i);

return 0;
}


int OldFuncName (int param1, int param2)
{

return (param1+param2);

}
------------------------

So the old functions still exist under their old name, but can be called by their new name.

But, if your old code is in a DLL, and you want to write new code to call that DLL, (for example).
You would have to include the header file with the old declarations in them, and then a new header file with the defines for the new names in. Then your new source code can call the old DLL functions using the new names.
// Untested Code Snippet

#include "OldDLLFunctionNames.h"

#define OldFn1 (NewFn1)
#define OldFn2 (NewFn2)

The disadvantage is that this header file becomes reliant upon the other one not changing the names of functions.
So now you have 2 header files to maintain for one set of functions.

Another way you could possibly achieve it, but you must make some assumptions here too...

If your VISA DLL exists and is 'permanent', but you have new source code / project that wants to call those functions...
You can dynamically load the DLL within your source code, and then search through the loaded module looking for the Old Named Functions. This would return pointers to the functions in memory and you can call them whatever you like. The assumptions made here are that the function definitions cannot change, since your new source code is reliant on the names and parameter types. This method though means that you do not need to include the DLL header files, or Library file...

More untested code.....

------
handle=LoadLibrary(YOUR_DLL_NAME);

NEW_FN_PTR_1=(fnPtr)GetProcAddress(handle,"OldFn1");

NEW_FN_PTR_2=(fnPtr)GetProcAddress(handle,"OldFn2");

NEW_FN_PTR_3=(fnPtr)GetProcAddress(handle,"OldFn3");

And then called via

a = NEW_FN_PTR (param1, param2)

-----------


Hope this helps more than confuses...
After writing all that, and re-reading your original question, I am sure I missed the plot completely...


Chris
0 Kudos
Message 3 of 4
(3,335 Views)
First I will say thanks for your help and your code.I learn more from your
code.
Send I must say sorry for my question and what i have post.
My option is I have made the code running successfullyuse the below code

#define star_Init star1055_signal_Init
#define start_Close star1055_signal_Close
.....
ViStatus _VI_FUNC star1055_signal_Init(( ViRsrc rsrcName, ViBoolean
id_query,ViBoolean reset,ViSession _VI_FAR *vi);
ViStatus _VI_FUNC star1055_signal_Close(ViSession vi);

this is the driver head file for the instrument star1055,a card my company
want to develop.
Then our application software programmer can use star_Init And star_Close
But if there is handrands of function,I have to define hundards of new
function name.
So I think i can write only one statments is
#defi
ne star star1055_signal,but when i do this,And use start_Init in the
applcation ,I got a error.

That is all. Wish your help again. Thanks a lot.
0 Kudos
Message 4 of 4
(3,335 Views)