Implementation of Win32Api with "WNetUseConnection"

M

MicMCdo

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top