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.
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?
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.
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.
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.
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.
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.
Bookmarks