# Implementation of Win32Api with "WNetUseConnection"

**URL:** <https://www.ruby-forum.com/t/implementation-of-win32api-with-wnetuseconnection/128271>\
**Category:** Ruby\
**Created:** [February 6, 2008, 10:15am UTC](https://www.ruby-forum.com/t/implementation-of-win32api-with-wnetuseconnection/128271 "2008-02-06T10:15:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 6, 2008, 10:15am UTC](https://www.ruby-forum.com/t/implementation-of-win32api-with-wnetuseconnection/128271/1 "2008-02-06T10:15:47Z")

</div>

Hi!

I am new on RUBY and I have difficulty with the Win32API call.

I receive thise message : “rb18.tmp:43:in `call’: can’t convert  
NETRESSOURCE into Integer (TypeError)”

How I send a struture in the declaration of the API fouction? It is  
not an Integer and not an String…  
Api\_ConnectIPC = Win32API.new( ‘mpr’, ‘WNetUseConnection’,  
[‘P’,‘P’,‘P’,‘P’,‘P’,‘P’,‘P’,‘P’], ‘L’

That is my code :

require ‘Win32API’

#DECLARATION DES CLASSES ET CONSTANTE  
NO\_ERROR = 0  
CONNECT\_LOCALDRIVE = 256  
CONNECT\_REDIRECT = 128  
RESOURCE\_GLOBALNET = ‘2’.hex  
RESOURCETYPE\_DISK = ‘1’.hex  
RESOURCEDISPLAYTYPE\_SHARE = ‘3’.hex  
RESOURCEUSAGE\_CONNECTABLE = ‘1’.hex  
CONNECT\_UPDATE\_PROFILE = 1

class NETRESSOURCE

attr\_accessor :dwScope, :dwType, :dwDisplayType, :dwUsage, :pLocalName,  
:pRemoteName, :pComment, :pProvider  
def initialize  
@dwScope = @dwType = @dwDisplayType = @dwUsage = @pLocalName=  
@pRemoteName = @pComment = @pProvider = “”  
end  
end

#ICI Je déclare mon API qui deviens un Objet  
Api\_ConnectIPC = Win32API.new( ‘mpr’, ‘WNetUseConnection’,  
[‘P’,‘P’,‘P’,‘P’,‘P’,‘P’,‘P’,‘P’], ‘L’ )

#Ici je déclare une fonction qui va utilisé l’Objet  
def Connect\_to\_server(server, user, password)  
serveur\_cible = NETRESSOURCE.new  
serveur\_cible.dwScope = RESOURCE\_GLOBALNET  
serveur\_cible.dwType = RESOURCETYPE\_DISK  
serveur\_cible.dwDisplayType = RESOURCEDISPLAYTYPE\_SHARE  
serveur\_cible.dwUsage = RESOURCEUSAGE\_CONNECTABLE  
serveur\_cible.pLocalName = nil  
serveur\_cible.pRemoteName = server  
lpResult = nil

hwndOwner = “”  
dwFlags = CONNECT\_REDIRECT  
lpAccessName = " " \* 32  
lpBufferSize = lpAccessName.length

rep = Api\_ConnectIPC.call(hwndOwner, serveur\_cible, user, password,  
dwFlags, lpAccessName, lpBufferSize, lpResult )  
end

And I receive this message : /rb18.tmp:43:in `call’: can’t convert  
NETRESSOURCE into Integer (TypeError)

Thanks for your help
