Implementation of Win32Api with "WNetUseConnection"

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs