Ayuda con Migracion de VB6 a .NET y APIs

10/11/2004 - 19:40 por Gabriel | Informe spam
Hola!

Tengo una mini aplicacion en VB6 que abre una pagina web y rellena un
formulario enviando los codigos de teclas correspondientes para cada
campo.. funciona perfectamente...

Estoy intentando migrar la aplicacion para VB.NET, y ejecuté el programa de
migración el cual me generó un proyecto nuevo.

Aunque todo compila perfectamente, sin errores, al llegar a una parte del
programa que llama a una funcion que anteriormente (en vb6) llamaba a una
api que envia codigo de teclas a una ventana, todo se congela y no pasa de
alli.
El lugar en donde se congela es el siguiente:

Call SendKeyString(nTela, "{TAB 4}")
System.Windows.Forms.Application.DoEvents()


Y la funcion es la siguiente:


Private Sub SendKeyString(ByRef AppName As String, ByRef KeyString As
String)
On Error GoTo Error_SendKeyString
AppActivate(AppName)
System.Windows.Forms.Application.DoEvents()
System.Windows.Forms.SendKeys.Send(KeyString)
Exit Sub

Error_SendKeyString:
MsgBox("Erro em SendKeyString - Err =" & Str(Err.Number))
End
End Sub

A que se debe esto?????.

Generé un ejecutable y lo corrí. Aparece la primera pantalla y cuando
intenta seguir (supongo que cuando pasa por la rutina anterior) da el
siguiente error:

"No fue encontrado ningun nombre de archivo o conjunto de modulos (assembly)
Microsoft.VisualBasic.Compatibility, ni ninguna de sus dependencias"

************** Texto de Exceção **************
System.IO.FileNotFoundException: Não foi encontrado nenhum nome de arquivo
ou de conjunto de módulos (assembly) Microsoft.VisualBasic.Compatibility,
nem nenhuma de suas dependências.
Nome do arquivo: "Microsoft.VisualBasic.Compatibility"
at ICMSWeb.frmICMSWeb.cmdIntegra_Click(Object eventSender, EventArgs
eventArgs)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)

Bueno, como se poco y nada de .NET estoy pidiendo ayuda para ver que puede
ser

Gracias,

Gabriel.
 

Leer las respuestas

#1 Gabriel
10/11/2004 - 19:45 | Informe spam
La siguiente es el modulo (ya transformado de VB6 a .NET que tiene las
declaraciones de las APIs que uso)

Option Strict Off
Option Explicit On
Module mdlICMSWeb
Public Declare Function GetClassName Lib "user32" Alias
"GetClassNameA"(ByVal hwnd As Integer, ByVal lpClassName As String, ByVal
nMaxCount As Integer) As Integer

Public Declare Function GetDesktopWindow Lib "user32" () As Integer

Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Integer,
ByVal wCmd As Integer) As Integer

Public Declare Function GetWindowLong Lib "user32" Alias
"GetWindowLongA"(ByVal hwnd As Integer, ByVal nIndex As Integer) As Integer

Public Declare Function GetWindowText Lib "user32" Alias
"GetWindowTextA"(ByVal hwnd As Integer, ByVal lpString As String, ByVal cch
As Integer) As Integer

Public Declare Function PostMessage Lib "user32" Alias
"PostMessageA"(ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As
Integer, ByVal lParam As Integer) As Integer

Public Declare Function ShellExecute Lib "shell32.dll" Alias
"ShellExecuteA"(ByVal hwnd As Integer, ByVal lpOperation As String, ByVal
lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String,
ByVal nShowCmd As Integer) As Integer

Public Declare Sub SetWindowPos Lib "user32" (ByVal hwnd As Integer, ByVal
hWndInsertAfter As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal cx
As Integer, ByVal cy As Integer, ByVal wFlags As Integer)

Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Integer)

'Public Const GW_HWNDFIRST = 0
'Public Const GW_HWNDLAST = 1
Public Const GW_HWNDNEXT As Short = 2
'Public Const GW_HWNDPREV = 3
Public Const GW_OWNER As Short = 4
Public Const GW_CHILD As Short = 5

Public Const HWND_TOPMOST As Short = -1
'Public Const HWND_NOTOPMOST = -2
Public Const SWP_NOSIZE As Short = &H1s
Public Const SWP_NOMOVE As Short = &H2s
Public Const SWP_NOACTIVATE As Short = &H10s
Public Const SWP_SHOWWINDOW As Short = &H40s

Public Const WS_CANCELMODE As Integer = &H1Fs
Public Const WM_CLOSE As Integer = &H10s
Public Const WS_DISABLED As Integer = &H8000000
Public Const GWL_STYLE As Integer = -16

Public Const WM_SYSCOMMAND As Short = &H112s
Public Const SC_MAXIMIZE As Integer = &HF030

Public nTela As String
Public hTela As Integer
Function FindWindowLike(ByVal hWndStart As Integer, ByRef WindowText As
String, ByRef Classname As String) As Integer
Dim hwnd As Integer
Dim sWindowText As String
Dim sClassname As String
Dim rGWT As Integer

'Hold the level of recursion and
'hold the number of matching windows
Static level As Short

'Initialize if necessary. This is only executed
'when level = 0 and hWndStart = 0, normally
'only on the first call to the routine.
If level = 0 Then
If hWndStart = 0 Then hWndStart = GetDesktopWindow()
End If

'Increase recursion counter
level = level + 1

'Get first child window
hwnd = GetWindow(hWndStart, GW_CHILD)

Do Until hwnd = 0

'Search children by recursion
Call FindWindowLike(hwnd, WindowText, Classname)

'Get the window text and class name
sWindowText = Space(255)
rGWT = GetWindowText(hwnd, sWindowText, 255)
sWindowText = Left(sWindowText, rGWT)

sClassname = Space(255)
rGWT = GetClassName(hwnd, sClassname, 255)
sClassname = Left(sClassname, rGWT)

'Check if window found matches the search parameters
If (sWindowText Like WindowText) And (sClassname Like Classname) Then
FindWindowLike = hwnd
hTela = hwnd
nTela = sWindowText
'uncommenting the next line causes the routine to
'only return the first matching window.
'Exit Do

End If

'Get next child window
hwnd = GetWindow(hwnd, GW_HWNDNEXT)

Loop

'Reduce the recursion counter
level = level - 1

End Function
Function EndTask(ByRef Whnd As Integer) As Object
'Do not close this window
If Whnd = frmICMSWeb.DefInstance.Handle.ToInt32 Then Exit Function

'Do not close this window's child
' (Do it without API)
If GetWindow(Whnd, GW_OWNER) = frmICMSWeb.DefInstance.Handle.ToInt32 Then
Exit Function

'Do not close if disabled
If (GetWindowLong(Whnd, GWL_STYLE) And WS_DISABLED) Then Exit Function

PostMessage(Whnd, WS_CANCELMODE, 0, 0)
PostMessage(Whnd, WM_CLOSE, 0, 0)
End Function
Function FechaTelas() As Object
Call FindWindowLike(0, "GUIA*", "*")
If nTela <> "" Then
EndTask(hTela)
End If

Call FindWindowLike(0, "Secretaria*", "*")
If nTela <> "" Then
EndTask(hTela)
End If
End Function

Preguntas similares