Results 1 to 13 of 13

Thread: [RESOLVED] ??Cannot define a Public user-defined type within a private object module??

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2005
    Posts
    117

    Resolved [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:
    1. Compile error:
    2.  
    3. Cannot define a Public user-defined type within a private object module

    on this line:
    VB Code:
    1. Type PROCESSENTRY32


    Can anyone tell me how to fix this?


    source:
    VB Code:
    1. 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
    2. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    3. 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
    4.  
    5. Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
    6. Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
    7. Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
    8. Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, lProcessID As Long) As Long
    9. Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    10. Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    11.  
    12.  
    13. Private winHwnd1 As Long
    14. Private winHwnd2 As Long
    15. Const SW_SHOWNORMAL = 1
    16. Const WM_CLOSE = &H10
    17.  
    18. Type PROCESSENTRY32
    19.     dwSize As Long
    20.     cntUsage As Long
    21.     th32ProcessID As Long
    22.     th32DefaultHeapID As Long
    23.     th32ModuleID As Long
    24.     cntThreads As Long
    25.     th32ParentProcessID As Long
    26.     pcPriClassBase As Long
    27.     dwFlags As Long
    28.     szexeFile As String * 6400
    29. End Type
    30.  
    31.  
    32. Public Function StopApp(myName As String) As Boolean
    33.     Const PROCESS_ALL_ACCESS = 0
    34.     Dim uProcess As PROCESSENTRY32
    35.     Dim rProcessFound As Long
    36.     Dim hSnapshot As Long
    37.     Dim szExename As String
    38.     Dim exitCode As Long
    39.     Dim myProcess As Long
    40.     Dim AppKill As Boolean
    41.     Dim appCount As Integer
    42.     Dim i As Integer
    43.     On Local Error GoTo Finish
    44.     appCount = 0
    45.    
    46.     Const TH32CS_SNAPPROCESS As Long = 2&
    47.    
    48.     uProcess.dwSize = Len(uProcess)
    49.     hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
    50.     rProcessFound = ProcessFirst(hSnapshot, uProcess)
    51.    
    52.     Do While rProcessFound
    53.         i = InStr(1, uProcess.szexeFile, Chr(0))
    54.         szExename = LCase$(Left$(uProcess.szexeFile, i - 1))
    55.         If Right$(szExename, Len(myName)) = LCase$(myName) Then
    56.             StopApp = True
    57.             appCount = appCount + 1
    58.             myProcess = OpenProcess(PROCESS_ALL_ACCESS, False, uProcess.th32ProcessID)
    59.             AppKill = TerminateProcess(myProcess, exitCode)
    60.             Call CloseHandle(myProcess)
    61.         End If
    62.         rProcessFound = ProcessNext(hSnapshot, uProcess)
    63.     Loop
    64.  
    65.     Call CloseHandle(hSnapshot)
    66. Finish:
    67. End Function
    68.  
    69.  
    70.  
    71.  
    72.  
    73. Private Sub CloseIt_Click()
    74.     StopApp (App.Path & "\portablewebap\portablewebap.exe")
    75.     StopApp (App.Path & "\portablefirefox\PortableFirefox.exe")
    76.     Unload Me
    77. End Sub
    78.  
    79. Private Sub OpenIt_Click()
    80.     winHwnd1 = ShellExecute(Me.hwnd, "open", App.Path & "\portablewebap\portablewebap.exe", vbNullString, App.Path & "\portablewebap\", SW_SHOWNORMAL)
    81.     winHwnd2 = ShellExecute(Me.hwnd, "open", App.Path & "\portablefirefox\PortableFirefox.exe", "-URL ""http://localhost:800"" -fullscreen", "C:\", SW_SHOWNORMAL)
    82. End Sub
    83.  
    84. Private Sub RestartIt_Click()
    85.     winHwnd2 = ShellExecute(Me.hwnd, vbNullString, "portablefirefox\PortableFirefox.exe", "-URL ""http://localhost:800"" -fullscreen", "C:\", SW_SHOWNORMAL)
    86. End Sub

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: ??Cannot define a Public user-defined type within a private object module??

    Just define it as a Public type.
    VB Code:
    1. Public Type PROCESSENTRY32
    2.     '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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  3. #3
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    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...
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  4. #4
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: ??Cannot define a Public user-defined type within a private object module??

    I'm not 100% but maybe....

    VB Code:
    1. Public Type PROCESSENTRY32

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2005
    Posts
    117

    Re: ??Cannot define a Public user-defined type within a private object module??

    I tried

    VB Code:
    1. Public Type PROCESSENTRY32

    but I get the same error message.

    BTW, why isn't the vbcode tag parsing in this forum?

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Aug 2005
    Posts
    117

    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

  8. #8
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    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.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Aug 2005
    Posts
    117

    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:
    1. Private Type PROCESSENTRY32
    2.     dwSize As Long
    3.     cntUsage As Long
    4.     th32ProcessID As Long
    5.     th32DefaultHeapID As Long
    6.     th32ModuleID As Long
    7.     cntThreads As Long
    8.     th32ParentProcessID As Long
    9.     pcPriClassBase As Long
    10.     dwFlags As Long
    11.     szexeFile As String * 6400
    12. End Type
    13.  
    14. 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
    15. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    16. 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
    17.  
    18. Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
    19. Private Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
    20. Private Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
    21. Private Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, lProcessID As Long) As Long
    22. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    23. Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    24.  
    25.  
    26. Private winHwnd1 As Long
    27. Private winHwnd2 As Long
    28. Const SW_SHOWNORMAL = 1
    29. Const WM_CLOSE = &H10
    30.  
    31.  
    32.  
    33. Private Function StopApp(myName As String) As Boolean
    34.     Const PROCESS_ALL_ACCESS = 0
    35.     Dim uProcess As PROCESSENTRY32
    36.     Dim rProcessFound As Long
    37.     Dim hSnapshot As Long
    38.     Dim szExename As String
    39.     Dim exitCode As Long
    40.     Dim myProcess As Long
    41.     Dim AppKill As Boolean
    42.     Dim appCount As Integer
    43.     Dim i As Integer
    44.     On Local Error GoTo Finish
    45.     appCount = 0
    46.    
    47.     Const TH32CS_SNAPPROCESS As Long = 2&
    48.    
    49.     uProcess.dwSize = Len(uProcess)
    50.     hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
    51.     rProcessFound = ProcessFirst(hSnapshot, uProcess)
    52.    
    53.     Do While rProcessFound
    54.         i = InStr(1, uProcess.szexeFile, Chr(0))
    55.         szExename = LCase$(Left$(uProcess.szexeFile, i - 1))
    56.         If Right$(szExename, Len(myName)) = LCase$(myName) Then
    57.             StopApp = True
    58.             appCount = appCount + 1
    59.             myProcess = OpenProcess(PROCESS_ALL_ACCESS, False, uProcess.th32ProcessID)
    60.             AppKill = TerminateProcess(myProcess, exitCode)
    61.             Call CloseHandle(myProcess)
    62.         End If
    63.         rProcessFound = ProcessNext(hSnapshot, uProcess)
    64.     Loop
    65.  
    66.     Call CloseHandle(hSnapshot)
    67. Finish:
    68. End Function
    69.  
    70.  
    71.  
    72.  
    73.  
    74. Private Sub CloseIt_Click()
    75.     StopApp (App.Path & "\portablewebap\portablewebap.exe")
    76.     StopApp (App.Path & "\portablefirefox\PortableFirefox.exe")
    77.     Unload Me
    78. End Sub
    79.  
    80. Private Sub OpenIt_Click()
    81.     winHwnd1 = ShellExecute(Me.hwnd, "open", App.Path & "\portablewebap\portablewebap.exe", vbNullString, App.Path & "\portablewebap\", SW_SHOWNORMAL)
    82.     winHwnd2 = ShellExecute(Me.hwnd, "open", App.Path & "\portablefirefox\PortableFirefox.exe", "-URL ""http://localhost:800"" -fullscreen", "C:\", SW_SHOWNORMAL)
    83. End Sub
    84.  
    85. Private Sub RestartIt_Click()
    86.     winHwnd2 = ShellExecute(Me.hwnd, vbNullString, "portablefirefox\PortableFirefox.exe", "-URL ""http://localhost:800"" -fullscreen", "C:\", SW_SHOWNORMAL)
    87. End Sub
    Last edited by singedpiper; Feb 2nd, 2006 at 12:03 AM.

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Aug 2005
    Posts
    117

    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.

  12. #12
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: [RESOLVED] ??Cannot define a Public user-defined type within a private object module??

    Have you tried my suggestion in post #3?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Aug 2005
    Posts
    117

    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
  •  



Click Here to Expand Forum to Full Width