Archive: Problem using System to Call COM DLL..


Problem using System to Call COM DLL..
Hi All,

I tried to write a Plugin DLL that used some COM
functions, but gave-up when it wouldn't work
for whatever reason.

So I wrote a regular DLL with one exported function,
to create a user, and to make sure that it "worked",
I wrote this test app:

#include <windows.h>
#include <stdio.h>


// Import function..
extern "C" __declspec(dllimport) int CreateUser();

int main(int argc, char* argv[])
{

int iRet;

iRet = CreateUser();
printf("iRet: %d\n", iRet);

return 0;
}

I ran the test app and it created the user
perfectly.

And when I try to use System to call it, I can't get it
to work. Here's what my test installer uses:

; Point to DLL location..
SetOutPath "C:\apache\Webserver\bin"

System::Call 'ServerSrv::CreateUser()'

( I know I wasn't doing anything with the return,
but I figured it wasn't that important )

Does the .lib have to also be in the same directory??

All my exported functions only return an int and
don't take any parameters.

Also, after I make the "Call", what is the best way to
"wait" until the function "finishes"?

If someone could point out what I'm doing wrong
I'd really appreciate it. :-)


Thanks,

Joe S.


There's no need for the .lib file. It only needs to find the DLL itself. It probably fails to find the DLL, though I see you did use SetOutPath. If that's not the problem, there might be a problem with the DLL itself. You said it uses COM and your other thread said a plug-in of yours fails to initialize COM. Maybe it's the same problem.

System::Call is fully synchronous. It doesn't open a new thread to call your function, so it'd "wait" for it to finish.


My DLL has to be working right because my test app
called the exported DLL function and it created the user
perfectly. :-\

One other thing, what's the exact syntax I need to use
for the System::Call, I haven't found a single example
where there are no input parameters and it returns an int.

Like:

int MyFunction()


Thanks,

Joe S.


Here's everything, the source to the DLL, the DLL,
the source to the test app that calls the DLL, and the
test app's .exe.

It creates a user "MobileSrvUser" and adds it to the
local Administrators group.

After you see that it works, you can just delete
that user.


Thanks,

Joe S.


To get the computer name, you can use the UserInfo plug-in.

You can't use printf, because there's no console. Use OutputDebugString and use DebugView to view what you print.

The wiki and the System documents have lots of examples. The readme explains everything you have to know. To call your function and have the result in $0, use:

System::Call "plugin::func()i.r0"

It works! :-)

After switching from using "if ( hr != S_OK )" to
"if ( ! SUCCEEDED(hr) )" mostly for the

hr = CoInitialize(NULL);

Doh! lol :-)

Everything seems to be working now, even with
my Plugin DLL! :-)

There is one exported function that keeps failing in
my Plugin DLL, but the regular DLL version,
where I use System::Call, works fine, so I'll
probably go with using that. :-)

Thanks for everyones help! :-)

Joe S.