Warning C4047 : '=': 'int' differs in levels of indirection from 'int *' - c

I am working on this code:
BOOL CALLBACK bWSStatus(HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
static int npFlag;
switch (iMsg)
{
case WM_INITDIALOG:
npFlag = (int *)lParam;//Geht in Ordnung, der Wert auf den der Zeiger lParam zeigt ist für npFlag relevant
...
I am getting this warning Warning C4047 : '=': 'int' differs in levels of indirection from 'int *'. Can someone please explain it?

Translation of the comment by Google is
Okay, the value pointed to by the lParam pointer is relevant for npFlag
It seams you forgot to dereference the pointer.
// add * to dereference the pointer
npFlag = *(int *)lParam;

Related

Undefined reference to `StringCbPrintfW' when compiling Win32 app

I'm trying to compile a Win32 app with MinGW, whose code can be found here. The source code compiles into an object just fine, but when I try and link it, this happens:
> gcc -o bin\updown.exe obj\updown.o -s -lcomctl32 -Wl,--subsystem,windows
obj\updown.o:updown.c:(.text+0x3ac): undefined reference to `StringCbPrintfW'
collect2.exe: error: ld returned 1 exit status
The only time this function appears is in the following snippet:
#include <windows.h>
#include <commctrl.h>
#include <strsafe.h>
...
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam) {
LPNMUPDOWN lpnmud;
UINT code;
switch(msg) {
...
case WM_NOTIFY:
...
const int asize = 4;
wchar_t buf[asize];
size_t cbDest = asize * sizeof(wchar_t);
StringCbPrintf(buf, cbDest, L"%d", value);
SetWindowText(hStatic, buf);
}
break;
...
}
...
}
Your project can define STRSAFE_LIB before including strsafe.h, and then link to strsafe.lib. Note that strsafe.h will use a #pragma comment(lib, "strsafe.lib") statement if STRSAFE_LIB is defined, but I don't know if that pragma works in MinGW or not, so you may have to link to the .lib manually.

BOOL not recognized as data type (C...?) [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I'm trying to compile an application from source code with Visual Studio 2015 Enterprise. I've run into some problems.
When I try to compile, I get several errors related to BOOL being an undefined type. I've tried including winmindef.h and windef.h to no avail. Here's some of the function declarations in the code that throw errors:
void GetCheatName ( int CheatNo, char * CheatName, int CheatNameLen );
BOOL LoadCheatExt ( char * CheatName, char * CheatExt, int MaxCheatExtLen);
void RefreshCheatManager ( void );
void SaveCheatExt ( char * CheatName, char * CheatExt );
BOOL TreeView_GetCheckState(HWND hwndTreeView, HTREEITEM hItem);
BOOL TreeView_SetCheckState(HWND hwndTreeView, HTREEITEM hItem, BOOL fCheck);`
When I include the following in the .h file, the problem is still not resolved
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
typedef int BOOL;
If it helps, I am trying to compile PJ64, and may need to change some setting in order to compile, but I'm not sure which.
Any help at all is appreciated!
---UPDATE---
Here are the complete compile errors (I've omitted most of the warnings):
1>cl : Command line warning D9007: '/Gm' requires '/Zi or /ZI'; option ignored
1> Cheat.c
1>Cheat.c(55): error C2059: syntax error: '<parameter-list>'
1>Cheat.c(56): error C2059: syntax error: '{'
1>Cheat.c(233): warning C4267: '=': conversion from 'size_t' to 'WORD', possible loss of data
1>Cheat.c(326): warning C4267: '=': conversion from 'size_t' to 'WORD', possible loss of data
1>Cheat.c(346): warning C4267: '=': conversion from 'size_t' to 'WORD', possible loss of data
1>Cheat.c(982): error C2059: syntax error: '<parameter-list>'
1>Cheat.c(998): error C2059: syntax error: '{'
1>Cheat.c(999): error C2449: found '{' at file scope (missing function header?)
1>Cheat.c(1012): error C2059: syntax error: '}'
The complete code for the project I am trying to compile can be found here.
This is -part- of the code that was compiled and threw the above errors. I've left the vast majority of the code out because it is too lengthy to include here. I've left comments indicating which lines threw errors.
#include <Windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <windef.h>
#include <stdio.h>
#include "main.h"
#include "cheats.h"
#include "cpu.h"
#include "resource.h"
#define UM_CHECKSTATECHANGE (WM_USER + 100)
#define UM_CHANGECODEEXTENSION (WM_USER + 101)
#define IDC_MYTREE 0x500
#define MaxCheats 300
#define SelectCheat 1
#define EditCheat 2
#define NewCheat 3
HWND hManageWindow = NULL;
HWND hSelectCheat, hAddCheat, hCheatTree;
CHEAT_CODES Codes[MaxCheats];
int NoOfCodes;
void GetCheatName ( int CheatNo, char * CheatName, int CheatNameLen );
BOOL LoadCheatExt ( char * CheatName, char * CheatExt, int MaxCheatExtLen);
void RefreshCheatManager ( void );
void SaveCheatExt ( char * CheatName, char * CheatExt );
BOOL TreeView_GetCheckState(HWND hwndTreeView, HTREEITEM hItem); //(line 55, error thrown.)
BOOL TreeView_SetCheckState(HWND hwndTreeView, HTREEITEM hItem, BOOL fCheck); //(line 56)
LRESULT CALLBACK ManageCheatsProc (HWND, UINT, WPARAM, LPARAM );
void ApplyCheats (void) {
//lots 'o code
}
BOOL CheatActive (char * Name) {
//more code
}
LRESULT CALLBACK CheatsCodeExProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
//Too much code to contain in this post...
}
LRESULT CALLBACK CheatsCodeQuantProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
//code
}
//Because of the inmensity of code, I will skip to the lines that throw errors.
BOOL TreeView_GetCheckState(HWND hwndTreeView, HTREEITEM hItem) { //line 982, error thrown.
//code here
}
BOOL TreeView_SetCheckState(HWND hwndTreeView, HTREEITEM hItem, BOOL fCheck) //line 999, error thrown
{ //line 1000, error thrown
//Lots o code
} // line 1013, error thrown
If more code is desired, I'll gladly post!
I've checked the code you gave a link to.
BOOL type is properly included. To check that you can compile Cheat.c with /P option.
All the problems are caused by upgrade of the project from Visual Studio 6 to Visual Studio 2015.
If you will investigate the pre-processor ouput you will see the transformation:
BOOL TreeView_GetCheckState(HWND hwndTreeView, HTREEITEM hItem); //(line 55, error thrown.)
BOOL TreeView_SetCheckState(HWND hwndTreeView, HTREEITEM hItem, BOOL fCheck); //(line 56)
pre-processed to:
BOOL ((((UINT)(SendMessageA((HWND hwndTreeView), (0x1100 + 39), (WPARAM)(HTREEITEM hItem), 0xF000))) >> 12) -1);
BOOL { TVITEMA _ms_TVi; _ms_TVi.mask = 0x0008; _ms_TVi.hItem = (HTREEITEM hItem); _ms_TVi.stateMask = (0xF000); _ms_TVi.state = ((((BOOL fCheck)?2:1) << 12)); SendMessageA((HWND hwndTreeView), (0x1100 + 13), 0, (LPARAM)(TVITEMA *)&_ms_TVi);};
It's not what you expect to see in your function declarations.
Both of these TreeView_GetCheckState and TreeView_SetCheckState are standard macroses defined in CommCtrl.h. Remove your old functions and use these macroses.

Compiling with tidy-html5 static library in my own project

I tried to add tidy-html5 library in my projects. To start I just create a file named "clean.c" with only two includes :
#include <tidy.h>
#include <tidybuffio.h>
I used libtidys.a file and I copied it into libs directory in my project.
So I compiled the file that way :
$ gcc -ansi -pedantic -std=c99 -c -W -Wall -O -I/foo/bar/inc -I/usr/include/libxml2 -I/foo/bar/dependencies/tidy-html5/include -L/foo/bar/libs -ltidys clean.c -o clean.o
And here is the results :
In file included from /foo/bar/dependencies/tidy-html5/include/tidy.h:65:0,
from clean.c:1:
/foo/bar/dependencies/tidy-html5/include/tidyplatform.h:547:9: error: unknown type name 'uint'
typedef uint tchar; /* single, full character */
^
In file included from clean.c:1:0:
/foo/bar/dependencies/tidy-html5/include/tidy.h:368:13: error: unknown type name 'uint'
TIDY_EXPORT uint TIDY_CALL tidyErrorCount( TidyDoc tdoc );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:371:13: error: unknown type name 'uint'
TIDY_EXPORT uint TIDY_CALL tidyWarningCount( TidyDoc tdoc );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:374:13: error: unknown type name 'uint'
TIDY_EXPORT uint TIDY_CALL tidyAccessWarningCount( TidyDoc tdoc );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:377:13: error: unknown type name 'uint'
TIDY_EXPORT uint TIDY_CALL tidyConfigErrorCount( TidyDoc tdoc );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:469:13: error: unknown type name 'ulong'
TIDY_EXPORT ulong TIDY_CALL tidyOptGetDefaultInt( TidyOption opt );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:487:13: error: unknown type name 'ulong'
TIDY_EXPORT ulong TIDY_CALL tidyOptGetInt( TidyDoc tdoc, TidyOptionId optId );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:489:86: error: unknown type name 'ulong'
TIDY_EXPORT Bool TIDY_CALL tidyOptSetInt( TidyDoc tdoc, TidyOptionId optId, ulong val );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:594:13: error: unknown type name 'uint'
TIDY_EXPORT uint TIDY_CALL tidyGetByte( TidyInputSource* source );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:597:68: error: unknown type name 'uint'
TIDY_EXPORT void TIDY_CALL tidyUngetByte( TidyInputSource* source, uint byteValue );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:631:63: error: unknown type name 'uint'
TIDY_EXPORT void TIDY_CALL tidyPutByte( TidyOutputSink* sink, uint byteValue );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:643:44: error: unknown type name 'uint'
uint line, uint col, ctmbstr mssg );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:643:55: error: unknown type name 'uint'
uint line, uint col, ctmbstr mssg );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:646:44: error: unknown type name 'uint'
uint line, uint col, ctmbstr mssg, va_list args );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:646:55: error: unknown type name 'uint'
uint line, uint col, ctmbstr mssg, va_list args );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:649:49: error: unknown type name 'uint'
uint line, uint col, ctmbstr code, va_list args );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:649:60: error: unknown type name 'uint'
uint line, uint col, ctmbstr code, va_list args );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:653:51: error: unknown type name 'TidyReportFilter'
TidyReportFilter filtCallback );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:656:51: error: unknown type name 'TidyReportFilter2'
TidyReportFilter2 filtCallback );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:659:56: error: unknown type name 'TidyReportFilter3'
TidyReportFilter3 filtCallback );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:675:57: error: unknown type name 'uint'
typedef void (TIDY_CALL *TidyPPProgress)( TidyDoc tdoc, uint line, uint col, uint destLine );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:675:68: error: unknown type name 'uint'
typedef void (TIDY_CALL *TidyPPProgress)( TidyDoc tdoc, uint line, uint col, uint destLine );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:675:78: error: unknown type name 'uint'
typedef void (TIDY_CALL *TidyPPProgress)( TidyDoc tdoc, uint line, uint col, uint destLine );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:678:51: error: unknown type name 'TidyPPProgress'
TidyPPProgress callback );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:756:65: error: unknown type name 'uint'
tmbstr buffer, uint* buflen );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:908:13: error: unknown type name 'uint'
TIDY_EXPORT uint TIDY_CALL tidyNodeLine( TidyNode tnod );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:909:13: error: unknown type name 'uint'
TIDY_EXPORT uint TIDY_CALL tidyNodeColumn( TidyNode tnod );
^
In file included from clean.c:2:0:
/foo/bar/dependencies/tidy-html5/include/tidybuffio.h:27:5: error: unknown type name 'uint'
uint size; /**< # bytes currently in use */
^
/foo/bar/dependencies/tidy-html5/include/tidybuffio.h:28:5: error: unknown type name 'uint'
uint allocated; /**< # bytes allocated */
^
/foo/bar/dependencies/tidy-html5/include/tidybuffio.h:29:5: error: unknown type name 'uint'
uint next; /**< Offset of current input position */
^
/foo/bar/dependencies/tidy-html5/include/tidybuffio.h:40:59: error: unknown type name 'uint'
TIDY_EXPORT void TIDY_CALL tidyBufAlloc( TidyBuffer* buf, uint allocSize );
^
/foo/bar/dependencies/tidy-html5/include/tidybuffio.h:46:55: error: unknown type name 'uint'
uint allocSize );
^
/foo/bar/dependencies/tidy-html5/include/tidybuffio.h:52:47: error: unknown type name 'uint'
uint allocSize, uint chunkSize );
^
/foo/bar/dependencies/tidy-html5/include/tidybuffio.h:52:63: error: unknown type name 'uint'
uint allocSize, uint chunkSize );
^
/foo/bar/dependencies/tidy-html5/include/tidybuffio.h:61:70: error: unknown type name 'uint'
TIDY_EXPORT void TIDY_CALL tidyBufAttach( TidyBuffer* buf, byte* bp, uint size );
^
/foo/bar/dependencies/tidy-html5/include/tidybuffio.h:68:70: error: unknown type name 'uint'
TIDY_EXPORT void TIDY_CALL tidyBufAppend( TidyBuffer* buf, void* vp, uint size );
^
Makefile:16: recipe for target 'clean.o' failed
make[1]: *** [clean.o] Error 1
Makefile:26: recipe for target 'all' failed
make: *** [all] Error 1
So I've made a quick check and I noticed tidy.h file include "tidyplatform.h" which contains that :
#if defined(BE_OS) || defined(SOLARIS_OS) || defined(BSD_BASED_OS) || defined(OSF_OS) || defined(IRIX_OS) || defined(AIX_OS)
#include <sys/types.h>
#endif
#if !defined(HPUX_OS) && !defined(CYGWIN_OS) && !defined(MAC_OS_X) && !defined(BE_OS) && !defined(SOLARIS_OS) && !defined(BSD_BASED_OS) && !defined(OSF_OS) && !defined(IRIX_OS) && !defined(AIX_OS) && !defined(LINUX_OS)
# undef uint
typedef unsigned int uint;
#endif
#if defined(HPUX_OS) || defined(CYGWIN_OS) || defined(MAC_OS) || defined(BSD_BASED_OS) || defined(_WIN32)
# undef ulong
typedef unsigned long ulong;
#endif
I'm on GNU/Linux. So I think I can fix that by adding "defined(LINUX_OS)" in the first preprocessor instructions (I didn't try). But, thats strange because this library is heavily used so...did I miss something ?
Cheers

creating a win32 dll from the following code using Visual Studio Express 2012

I'm trying to build a standard win32 DLL from the following code. I know C# well, but I'm new to C. I'm getting all kinds of compiler errors and have been going at this for the last 4 hours. Could someone please help me put together this simple project? I would be very grateful.
dll.h
#ifndef _DLL_H_
#define _DLL_H_
#include <windows.h>
#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */
#define SHARED __attribute__((section(".shr"), shared))
DLLIMPORT BOOL InstallHook(int i);
DLLIMPORT BOOL UninstallHook();
static LRESULT CALLBACK MyWndProc(int nCode, WPARAM wParam, LPARAM lParam);
#endif /* _DLL_H_ */
dll.cpp
/* Replace "dll.h" with the name of your header */
#include "dll.h"
#include <stdio.h>
HHOOK hHook SHARED = NULL; // Handle des Hooks
HINSTANCE hInstance SHARED = NULL; // Handle der DLL
FILE *fp SHARED;
BOOL APIENTRY DllMain (HINSTANCE hInst /* Library instance handle. */ ,
DWORD reason /* Reason this function is being called. */ ,
LPVOID reserved /* Not used. */ )
{
hInstance = hInst;
/* Returns TRUE on success, FALSE on failure */
return TRUE;
}
static LRESULT CALLBACK MyWndProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode < 0)
CallNextHookEx(hHook, nCode, wParam, lParam);
CWPSTRUCT* cw = (CWPSTRUCT*)(lParam);
if ( (cw->message == WM_GETMINMAXINFO))
{
fprintf(fp, "GETMINMAX! \n"); // Never called!
}
return CallNextHookEx(hHook, nCode, wParam, lParam);
}
DLLIMPORT BOOL UninstallHook()
{
UnhookWindowsHookEx(hHook);
hHook = NULL;
return TRUE;
}
DLLIMPORT BOOL InstallHook(int i)
{
fp = fopen("log.txt", "w");
hHook = SetWindowsHookEx(WH_CALLWNDPROC, MyWndProc, hInstance, i);
if (hHook == NULL)
return FALSE;
return TRUE;
}
Errors being received are:
Error 14 error C2086: 'int DLLIMPORT' : redefinition
r:\dev\cpp\win32project4\win32project4\dll.cpp 42 1 Win32Project4
Error 9 error C2086: 'int SHARED' : redefinition r:\dev\cpp\win32project4\win32project4\dll.cpp 10 1 Win32Project4
Error 10 error C2146: syntax error : missing ';' before identifier 'BOOL' r:\dev\cpp\win32project4\win32project4\dll.cpp 35 1 Win32Project4
Error 12 error C2146: syntax error : missing ';' before identifier 'BOOL' r:\dev\cpp\win32project4\win32project4\dll.cpp 42 1 Win32Project4
Error 2 error C2146: syntax error : missing ';' before identifier 'SHARED' r:\dev\cpp\win32project4\win32project4\dll.cpp 8 1 Win32Project4
Error 4 error C2146: syntax error : missing ';' before identifier 'SHARED' r:\dev\cpp\win32project4\win32project4\dll.cpp 9 1 Win32Project4
Error 7 error C2146: syntax error : missing ';' before identifier 'SHARED' r:\dev\cpp\win32project4\win32project4\dll.cpp 10 1 Win32Project4
Error 6 error C2374: 'SHARED' : redefinition; multiple initialization r:\dev\cpp\win32project4\win32project4\dll.cpp 9 1 Win32Project4
Error 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int r:\dev\cpp\win32project4\win32project4\dll.cpp 8 1 Win32Project4
Error 5 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int r:\dev\cpp\win32project4\win32project4\dll.cpp 9 1 Win32Project4
Error 8 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int r:\dev\cpp\win32project4\win32project4\dll.cpp 10 1 Win32Project4
Error 11 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int r:\dev\cpp\win32project4\win32project4\dll.cpp 35 1 Win32Project4
Error 13 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int r:\dev\cpp\win32project4\win32project4\dll.cpp 42 1 Win32Project4
18 IntelliSense: a function declared 'dllimport' may not be defined r:\dev\cpp\Win32Project4\Win32Project4\dll.cpp 35 16 Win32Project4
19 IntelliSense: a function declared 'dllimport' may not be defined r:\dev\cpp\Win32Project4\Win32Project4\dll.cpp 42 16 Win32Project4
15 IntelliSense: expected a ';' r:\dev\cpp\Win32Project4\Win32Project4\dll.cpp 8 13 Win32Project4
16 IntelliSense: expected a ';' r:\dev\cpp\Win32Project4\Win32Project4\dll.cpp 9 21 Win32Project4
17 IntelliSense: expected a ';' r:\dev\cpp\Win32Project4\Win32Project4\dll.cpp 10 10 Win32Project4

sendmessage callback error in visual studio 2012

sendmessage callback error in visual studio 2012
I am recieving following errors in this C function?
error C2220: warning treated as error - no 'object' file generated
warning C4100: 'wParam' : unreferenced formal parameter
warning C4100: 'hwnd' : unreferenced formal parameter
LRESULT CALLBACK WndProc (HWND hwnd,UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) {
case WM_COPYDATA:
{
COPYDATASTRUCT* copy_data = (COPYDATASTRUCT*)(lParam);
const char* str = (const char* )(copy_data->lpData);
/* Also fixed the parameter list for "%.*s" */
printf("Message (%u): %.*s\n", copy_data->dwData, (int)copy_data->cbData, str);
}
}
}
The error is that you told the compiler to treat warnings as errors, and you have two warnings about arguments that is not used in the function.
The simplest solution is to actually skip naming those arguments, like so:
LRESULT CALLBACK WndProc (HWND, UINT message, WPARAM, LPARAM lParam)
For a solution working in C, then you have to actually use the arguments, even if you don't do anything with them. This can be done with e.g. using them in an expression and throw away the result, like
(void) hwnd;
(void) wParam;
Or use the macros defined in winnt.h (which should be included for you by default) for this:
UNREFERENCED_PARAMETER(hwnd);
UNREFERENCED_PARAMETER(wParam);
See e.g. this article.

Resources