Jump to content

Call C function from Php

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
anis0408

anis0408

    Newbie

  • Members
  • Pip
  • 2 posts
Hello, could you please me help about that ?

In fact, I just need to call a C function which is in a library. I tried this :
system('rundll32.exe library.dll,function 20 ');

I can call my function but I can't pass 20 as an argument to my C function.

I also checked php extensions but clearly that is not what I need

Many thanks in advance for your answers

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
Your question does not relate to PHP at all,

anis0408 said:

but I can't pass 20 as an argument to my C function.

Could you explain better the problem?
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
dbug

dbug

    Programmer

  • Members
  • PipPipPipPip
  • 155 posts
The functions called from rundll32 must be explicitly implemented to be called from it. They must use stdcall convention and the following signature:

void CALLBACK Function(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow);
The important part is the "lpszCmdLine" argument. It receives the arguments passed to rundll32 (all you put after the dll and function name) as a text string that the dll must parse before using them. In your case I supose you have a function like this:

void CALLBACK Function(UINT value);
In this case you should write an intermediate function with the first signature that parses the lpszCmdLine argument and converts it to an integer and then calls the second function with the resulting value.

The RunDll32 utility is not designed to call arbitrary functions. You can read more about it here.