Jump to content

Calling Network functions with CIN


Recommended Posts

Hi everybody!

I've a problem with calling Windows API: I need to work with Active Directories on Windows Server 2003. On start I want to login with the LogonUser function of the advapi32.dll.

I tried to call the function via LV dll-call without success (I use LV 7.1). After this I wrote an CIN for this. But it don't makes me happy. I alwas get an error (not enough space). I'm confess that my C is not 100% good, but it's sufficed up to now.

Jens

Download File:post-3936-1139819885.zip

Link to comment
Hi everybody!

I've a problem with calling Windows API: I need to work with Active Directories on Windows Server 2003. On start I want to login with the LogonUser function of the advapi32.dll.

I tried to call the function via LV dll-call without success (I use LV 7.1). After this I wrote an CIN for this. But it don't makes me happy. I alwas get an error (not enough space). I'm confess that my C is not 100% good, but it's sufficed up to now.

Jens

First:

GetIndirectFunctionHandle and friends were only meant and available for LabVIEW for Windows 3.1.

Second:

In order to call a function over a pointer variable, this pointer variable must be properly typed either through the declaration itself or a typecast at the point of call. Otherwise the C compiler can't know how to pass the parameters and what to expect as return value.

if (!(UsernameCStr == (char *)DSNewPtr(*Username)+1)) {cinErr = mFullErr; goto out; }

will allocate not what you think it does. It will use the pointer value in the handle as length indicator and attempt to allocate potentially a huge amount of memory running out of memory quite soon.

You should make this read

if (!(UsernameCStr == (char *)DSNewPtr(LStrLen(*Username))+1)) {cinErr = mFullErr; goto out; }

and even better would be to allocate a cleared memory area with DSNewPClr().

Instead configuring a CallLibraryNode with advapi32.dll, LogonUserA, stdcall calling convention, the string parameters as C string pointers and the two constants as uInt32 and the last one as an uInt32 passed as pointer, simply should work fine.

Last but not least you will leak a handle here with LogonUser returning the phToken that never gets closed.

Rolf Kalbermatter

Download File:post-349-1140011772.vi

Link to comment
You should make this read

if (!(UsernameCStr == (char *)DSNewPtr(LStrLen(*Username))+1)) {cinErr = mFullErr; goto out; }

and even better would be to allocate a cleared memory area with DSNewPClr().

Thank you. I modified the the command to

if (!(UsernameCStr = (char *)DSNewPClr(LStrLen(*Username)+1))) {cinErr = mFullErr; goto out; }

and the memory error is gone.

Instead configuring a CallLibraryNode with advapi32.dll, LogonUserA, stdcall calling convention, the string parameters as C string pointers and the two constants as uInt32 and the last one as an uInt32 passed as pointer, simply should work fine.
Yes, it's working.
Last but not least you will leak a handle here with LogonUser returning the phToken that never gets closed.

Rolf Kalbermatter

You are right, I can't close the handle. I tried a CallLibraryNode with kernel32.dll/CloseHandle but I get an error. So I included the line

CloseHandle(*phToken);

after the function call LogonUserA(..) in the CIN and it's working without error. This means I need to include my ActiveDirectory between these commands. But this is my next step.

Jens

Link to comment
You are right, I can't close the handle. I tried a CallLibraryNode with kernel32.dll/CloseHandle but I get an error. So I included the line

You probably tried to do some fancy datatype here. Just treat the handle as uInt32. In the Logon function this parameter is passed as Pointer to Value. In the CloseHandle case just as Value only since it is not a parameter by reference here.

Rolf Kalbermatter

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.