|
-
Feb 1st, 2006, 10:56 PM
#1
Thread Starter
Lively Member
[RESOLVED] ??Cannot define a Public user-defined type within a private object module??
When I try to compile my code, I get the following error:
VB Code:
Compile error:
Cannot define a Public user-defined type within a private object module
on this line:
Can anyone tell me how to fix this?
source:
VB Code:
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, lProcessID As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private winHwnd1 As Long
Private winHwnd2 As Long
Const SW_SHOWNORMAL = 1
Const WM_CLOSE = &H10
Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szexeFile As String * 6400
End Type
Public Function StopApp(myName As String) As Boolean
Const PROCESS_ALL_ACCESS = 0
Dim uProcess As PROCESSENTRY32
Dim rProcessFound As Long
Dim hSnapshot As Long
Dim szExename As String
Dim exitCode As Long
Dim myProcess As Long
Dim AppKill As Boolean
Dim appCount As Integer
Dim i As Integer
On Local Error GoTo Finish
appCount = 0
Const TH32CS_SNAPPROCESS As Long = 2&
uProcess.dwSize = Len(uProcess)
hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
rProcessFound = ProcessFirst(hSnapshot, uProcess)
Do While rProcessFound
i = InStr(1, uProcess.szexeFile, Chr(0))
szExename = LCase$(Left$(uProcess.szexeFile, i - 1))
If Right$(szExename, Len(myName)) = LCase$(myName) Then
StopApp = True
appCount = appCount + 1
myProcess = OpenProcess(PROCESS_ALL_ACCESS, False, uProcess.th32ProcessID)
AppKill = TerminateProcess(myProcess, exitCode)
Call CloseHandle(myProcess)
End If
rProcessFound = ProcessNext(hSnapshot, uProcess)
Loop
Call CloseHandle(hSnapshot)
Finish:
End Function
Private Sub CloseIt_Click()
StopApp (App.Path & "\portablewebap\portablewebap.exe")
StopApp (App.Path & "\portablefirefox\PortableFirefox.exe")
Unload Me
End Sub
Private Sub OpenIt_Click()
winHwnd1 = ShellExecute(Me.hwnd, "open", App.Path & "\portablewebap\portablewebap.exe", vbNullString, App.Path & "\portablewebap\", SW_SHOWNORMAL)
winHwnd2 = ShellExecute(Me.hwnd, "open", App.Path & "\portablefirefox\PortableFirefox.exe", "-URL ""http://localhost:800"" -fullscreen", "C:\", SW_SHOWNORMAL)
End Sub
Private Sub RestartIt_Click()
winHwnd2 = ShellExecute(Me.hwnd, vbNullString, "portablefirefox\PortableFirefox.exe", "-URL ""http://localhost:800"" -fullscreen", "C:\", SW_SHOWNORMAL)
End Sub
-
Feb 1st, 2006, 11:43 PM
#2
Re: ??Cannot define a Public user-defined type within a private object module??
Just define it as a Public type.
VB Code:
Public Type PROCESSENTRY32
'Blah, blah, b;ah...
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Feb 1st, 2006, 11:43 PM
#3
Re: ??Cannot define a Public user-defined type within a private object module??
Try putting those declarations in a module and set them as Public...
-
Feb 1st, 2006, 11:43 PM
#4
Re: ??Cannot define a Public user-defined type within a private object module??
I'm not 100% but maybe....
VB Code:
Public Type PROCESSENTRY32
-
Feb 1st, 2006, 11:50 PM
#5
Thread Starter
Lively Member
Re: ??Cannot define a Public user-defined type within a private object module??
I tried
VB Code:
Public Type PROCESSENTRY32
but I get the same error message.
BTW, why isn't the vbcode tag parsing in this forum?
-
Feb 1st, 2006, 11:51 PM
#6
Re: ??Cannot define a Public user-defined type within a private object module??
Is your code behind a form?
The forum was recently upgraded and the vbcode tags are needing repair. Should be fixes in a few days.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Feb 1st, 2006, 11:54 PM
#7
Thread Starter
Lively Member
Re: ??Cannot define a Public user-defined type within a private object module??
um, If I understand what that means correctly, yes.
it is in the code file corresponding to repertoire.frm
-
Feb 1st, 2006, 11:54 PM
#8
Re: ??Cannot define a Public user-defined type within a private object module??
Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, lProcessID As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
You can't just use.. Declare..
If it's in a form Use Private Declare ...
If it's in a Module (and it's being called from outside) Use Public Declare ...
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
If that's not a module and you want to keep it there, declare it Private, else move it to a Module
Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szexeFile As String * 6400
End Type
The same, Make this type Private if this is not a module, and Most important, this declaration, must be BEFORE the private declared functions that uses this UDT(at the top)
Last edited by jcis; Feb 1st, 2006 at 11:59 PM.
-
Feb 1st, 2006, 11:59 PM
#9
Thread Starter
Lively Member
Re: ??Cannot define a Public user-defined type within a private object module??
well, I just made everything Private, and the problem wen away. Now I have to see how it runs.
Here's my code as it stands, please tell me if I have any other Glaring errors:
VB Code:
Private Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szexeFile As String * 6400
End Type
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, lProcessID As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private winHwnd1 As Long
Private winHwnd2 As Long
Const SW_SHOWNORMAL = 1
Const WM_CLOSE = &H10
Private Function StopApp(myName As String) As Boolean
Const PROCESS_ALL_ACCESS = 0
Dim uProcess As PROCESSENTRY32
Dim rProcessFound As Long
Dim hSnapshot As Long
Dim szExename As String
Dim exitCode As Long
Dim myProcess As Long
Dim AppKill As Boolean
Dim appCount As Integer
Dim i As Integer
On Local Error GoTo Finish
appCount = 0
Const TH32CS_SNAPPROCESS As Long = 2&
uProcess.dwSize = Len(uProcess)
hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
rProcessFound = ProcessFirst(hSnapshot, uProcess)
Do While rProcessFound
i = InStr(1, uProcess.szexeFile, Chr(0))
szExename = LCase$(Left$(uProcess.szexeFile, i - 1))
If Right$(szExename, Len(myName)) = LCase$(myName) Then
StopApp = True
appCount = appCount + 1
myProcess = OpenProcess(PROCESS_ALL_ACCESS, False, uProcess.th32ProcessID)
AppKill = TerminateProcess(myProcess, exitCode)
Call CloseHandle(myProcess)
End If
rProcessFound = ProcessNext(hSnapshot, uProcess)
Loop
Call CloseHandle(hSnapshot)
Finish:
End Function
Private Sub CloseIt_Click()
StopApp (App.Path & "\portablewebap\portablewebap.exe")
StopApp (App.Path & "\portablefirefox\PortableFirefox.exe")
Unload Me
End Sub
Private Sub OpenIt_Click()
winHwnd1 = ShellExecute(Me.hwnd, "open", App.Path & "\portablewebap\portablewebap.exe", vbNullString, App.Path & "\portablewebap\", SW_SHOWNORMAL)
winHwnd2 = ShellExecute(Me.hwnd, "open", App.Path & "\portablefirefox\PortableFirefox.exe", "-URL ""http://localhost:800"" -fullscreen", "C:\", SW_SHOWNORMAL)
End Sub
Private Sub RestartIt_Click()
winHwnd2 = ShellExecute(Me.hwnd, vbNullString, "portablefirefox\PortableFirefox.exe", "-URL ""http://localhost:800"" -fullscreen", "C:\", SW_SHOWNORMAL)
End Sub
Last edited by singedpiper; Feb 2nd, 2006 at 12:03 AM.
-
Feb 2nd, 2006, 01:01 AM
#10
Re: ??Cannot define a Public user-defined type within a private object module??
Just a side note: When using only "Declare" with your API it designates Public implicitly. Its always a good idea to explicitly use Public or Private beforehand.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Feb 3rd, 2006, 12:42 AM
#11
Thread Starter
Lively Member
Re: ??Cannot define a Public user-defined type within a private object module??
well, it doesn't close the program, so I'm in for more debugging, but thanks for the help.
-
Feb 3rd, 2006, 12:45 AM
#12
Re: [RESOLVED] ??Cannot define a Public user-defined type within a private object module??
Have you tried my suggestion in post #3?
-
Feb 3rd, 2006, 02:37 AM
#13
Thread Starter
Lively Member
Re: [RESOLVED] ??Cannot define a Public user-defined type within a private object module??
would that really make a difference? I'm just calling them as private at the moment with the code in the form control, and I can't see why being public would change anything... elaborate, please?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|