C language > Beginner questions

Compiler trouble

(1/4) > >>

Zodra1:
I don't know what is wrong with me. After testing SQL ODBC connect I started to develop main application. I generated MDI app. with wizard. Iz compiled well until i added SQLAllocHandle. Below is code:

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>
#include <winuser.h>
#include <sql.h>
#include <sqlext.h>

#include <stdio.h>

#include "main.h"
#include "statusbar.h"
#include "toolbar.h"

HINSTANCE g_hInst;   // instance handle
HWND g_hWndFrame;   // main window handle
HWND g_hWndClient;   // mdi client window handle
HWND g_hWndToolBar;   // toolbar window handle
HWND g_hWndStatusBar;   // statusbar window handle
HBITMAP g_hBmp;   // toolbar button's bitmap

int numParts = 4; // number of sections for statusbar
// ODBC connection to Mafips30 database *************************************************************************
static void extract_error(
    char *fn,
    SQLHANDLE handle,
    SQLSMALLINT type);

    SQLHENV env;
    SQLHDBC dbc;
    SQLHSTMT stmt;
    SQLRETURN ret; /* ODBC API return status */
    SQLCHAR outstr[1024];
    SQLSMALLINT outstrlen;

  /* Allocate an environment handle */

SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);

// End od ODBC connect **********************************************************************************************

This line produced following errors:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>
#include <winuser.h>
#include <sql.h>
#include <sqlext.h>

#include <stdio.h>

#include "main.h"
#include "statusbar.h"
#include "toolbar.h"

HINSTANCE g_hInst;   // instance handle
HWND g_hWndFrame;   // main window handle
HWND g_hWndClient;   // mdi client window handle
HWND g_hWndToolBar;   // toolbar window handle
HWND g_hWndStatusBar;   // statusbar window handle
HBITMAP g_hBmp;   // toolbar button's bitmap

int numParts = 4; // number of sections for statusbar
// ODBC connection to Mafips30 database *************************************************************************
static void extract_error(
    char *fn,
    SQLHANDLE handle,
    SQLSMALLINT type);

    SQLHENV env;
    SQLHDBC dbc;
    SQLHSTMT stmt;
    SQLRETURN ret; /* ODBC API return status */
    SQLCHAR outstr[1024];
    SQLSMALLINT outstrlen;

  /* Allocate an environment handle */

SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);

// End od ODBC connect **********************************************************************************************
This line produced three errors (line 48)

D:\Pelles_Razvoj\MaFiP'S 3.0\mafips30\main.c(48): warning #2099: Missing type specifier.
D:\Pelles_Razvoj\MaFiP'S 3.0\mafips30\main.c(48): error #2001: Syntax error: expected ')' but found 'integer constant'.
D:\Pelles_Razvoj\MaFiP'S 3.0\mafips30\main.c(48): error #2120: Redeclaration of 'SQLAllocHandle' previously declared at C:\Program Files\PellesC\Include\Win\sql.h(433): found 'int __cdecl function()', expected 'short int __stdcall function(short int, void *, void * *)'.
D:\Pelles_Razvoj\MaFiP'S 3.0\mafips30\main.c(147): warning #2168: Operands of = have incompatible types 'int __stdcall function(HWND, long int)' and 'int __cdecl function(HWND, long int)'.
D:\Pelles_Razvoj\MaFiP'S 3.0\mafips30\main.c(534): warning #2030: = used in a conditional expression.
*** Error code: 1 ***

It would also be very helpful if someone could explain last two warning messages.


JohnF:
static void extract_error(
    char *fn,
    SQLHANDLE handle,
    SQLSMALLINT type);

The above is not correct - see if you can tell what's wrong. When you've corrected it see if it compiles better.

And this:
D:\Pelles_Razvoj\MaFiP'S 3.0\mafips30\main.c(534): warning #2030: = used in a conditional expression.

   if(i = 0) // this is most often a mistake so the compiler warns about it.

You probably want if(i == 0)

And this;
D:\Pelles_Razvoj\MaFiP'S 3.0\mafips30\main.c(147): warning #2168: Operands of = have incompatible types 'int __stdcall function(HWND, long int)' and 'int __cdecl function(HWND, long int)'.

There is a function for which the calling convention is not correct. I can't see the code, make sure that it is prefixed with the right one. Probably __cdecl

e.g.
int __cdecl myfunc(HWND h, long t)

John

Zodra1:
static void extract_error(
    char *fn,
    SQLHANDLE handle,
    SQLSMALLINT type);
Must admit, that I am too inexperienced in C to figure out what is wrong with function declaration. Not that i haven't tried.

Function call is:
EnumChildWindows(g_hWndClient, EnumChildDestroy, 0);

This was generated by MDI wizard; definition of EnumChildDestroy:
int EnumChildDestroy(HWND hwnd, LPARAM lParam);
and call:
EnumChildWindows(g_hWndClient, EnumChildDestroy, 0);

Can't find EnumChildWindows in the code; possible API call?

I will keep trying of course; but help is more than welcome.

Zodra1:
Function is API, i found declaration in winuser.h:
WINUSERAPI BOOL WINAPI EnumChildWindows(HWND,WNDENUMPROC,LPARAM);
It is BOOL-ean type, must be that those should be called differently?

JohnF:
EnumChildWindows() API is __stdcall. Are you compiling a Console app?

Console apps default to __cdecl.

Post the code. edit: If you are not bashful.

John

Navigation

[0] Message Index

[#] Next page

Go to full version