CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jan 2004
    Location
    Near Portland, OR
    Posts
    222

    [RESOLVED] SetWindowWord Getting Compile Error

    This should be a simple issue. This is in VB6.

    The declare statement is asserting an error when I try to compile with this message:

    Code:
    Compile Error:
    
    Constants, fixed-length strings, arrays, user-defined types and Declare statements not allowed as Public members of object modules
    The declare statements are:

    Code:
       Declare Function SetWindowWord Lib "User" (ByVal hwnd As Integer, ByVal Index As Integer, ByVal wNewWord As Integer) As Integer
       Const GWW_HWNDPARENT = (-8)
       Dim OriginalParenthWnd As Integer
    The only constant is on the next line. I'm a C/C++ programmer shoved into this program trying to meet a deadline. I'm bewildered about why this is causing the error.

    I've tried to comment out the other globals declared, but it still generates the same error message.

    Bill

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: SetWindowWord Getting Compile Error

    What type of project? What type of file is the Declare in? [e.g. Module, Class, Form] Is the declaration at the top of the file prior to the first sub or function?
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Jan 2004
    Location
    Near Portland, OR
    Posts
    222

    Re: SetWindowWord Getting Compile Error

    The project is a regular EXE. It is in a form and it is at the top of the file. There is another Dim above this one, but the error still happened when I commented that out.

  4. #4
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: SetWindowWord Getting Compile Error

    You will need to move the declare to the declaration section of a module, You will also need to make it public if you want to call it from your form.
    Always use [code][/code] tags when posting code.

  5. #5
    Join Date
    Jan 2004
    Location
    Near Portland, OR
    Posts
    222

    Re: SetWindowWord Getting Compile Error

    I thought the declare section was at the top of the file. This is the first three lines of code in the file (after a couple of comments):

    Code:
       Declare Function SetWindowWord Lib "User" (ByVal hwnd As Integer, ByVal Index As Integer, ByVal wNewWord As Integer) As Integer
       Const GWW_HWNDPARENT = (-8)
       Dim OriginalParenthWnd As Integer
    Everywhere else I've seen declare statements, they have been the first lines in the file. What is the syntax to declare it public? I have several examples of declares from this program and other VB programs in the suite of programs we're working on. I don't see a public keyword in any of the declare statements.

  6. #6
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: SetWindowWord Getting Compile Error

    use the same declare you already have but prefix it with Public.

    The declare section is at the top of the file but when you declare API functions you need to do those at the top of a module. You can of course have several of them in the same module. Just need to keep them all above any code for subs and functions.


    Code:
    Option Explicit
    
    Public Declare Function SetWindowWord Lib "User" (ByVal hwnd As Integer, ByVal Index As Integer, ByVal wNewWord As Integer) As Integer
    Public Const GWW_HWNDPARENT = (-8)
    Public OriginalParenthWnd As Integer
    I tested your code and if I place the code if a form the app will not compile. If I place the same code in a module it compiles fine.

    The example above shows how to set them public in a module.
    Always use [code][/code] tags when posting code.

  7. #7
    Join Date
    Jan 2004
    Location
    Near Portland, OR
    Posts
    222

    Re: SetWindowWord Getting Compile Error

    There is something other than the declaration wrong here. I stripped down the entire code in the form to just this line:

    Code:
    Public Declare Function SetWindowWord Lib "User" (ByVal hwnd As Integer, ByVal Index As Integer, ByVal wNewWord As Integer) As Integer
    The error is

    Constants,fixed-length strings, arrays, user-defined types and Declare statements not allowed as Public members of object modules

    I did copy this form from another project. I looked at the form in a separate text editor, I didn't see anything specific left in there from the original program.

    VB is driving me crazy!

    Bill

  8. #8
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: SetWindowWord Getting Compile Error

    As I said before place the declaration in a module.

    Remove it from your form, add it to a module and you should be fine.

    You will continue to see this error if you continue to try to setup your API functions in your form code. It should not be there.
    Always use [code][/code] tags when posting code.

  9. #9
    Join Date
    Jan 2004
    Location
    Near Portland, OR
    Posts
    222

    Re: SetWindowWord Getting Compile Error

    I see what you're talking about now. Some of the other VB programs in the project have modules that are nothing but declarations. I didn't understand why they did that. Now I know.

    Sorry, I didn't grok what you said earlier.

    Bill

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

Featured