Why doesn't this code compile?

Windows specific questions.
Post Reply
myndgrrrrrl
Posts: 11
Joined: Feb 09, 2022 0:03

Why doesn't this code compile?

Post by myndgrrrrrl »

I found a code in C language and decided to port to freebasic, however, when I compile it gives this error

Code: Select all

main.bas(17) error 73: Array access, index expected, before ')' in 'StretchDIBits(hDC,0,0,ScreenX,ScreenY,0,0,ResX,ResY,pixel,@bmi,0,SRCCOPY)'
How can i fix this?

the code in freebasic is this

Code: Select all

#include "windows.bi"
#define ResX 256
#define ResY 192

Dim As MSG msg
Dim As Integer
static As Integer pixel(ResX*ResY)
static As BITMAPINFO bmi = Type(sizeof(BITMAPINFOHEADER),ResX,ResY,1,32)
 
Dim As HWND hWnd = CreateWindowEx(0,"edit",0,(WS_OVERLAPPEDWINDOW Or WS_SYSMENU) - (WS_THICKFRAME) Or WS_VISIBLE,200,200,ResX,ResY,0,0,0,0)
Dim As HDC hDC = GetDC(hWnd)

of
PeekMessage(@msg,0,0,0,PM_REMOVE)
    Dim As Integer ScreenX = GetSystemMetrics(SM_CXSCREEN)
    Dim As Integer ScreenY = GetSystemMetrics(SM_CYSCREEN)
StretchDIBits(hDC,0,0,ScreenX,ScreenY,0,0,ResX,ResY,pixel,@bmi,0,SRCCOPY)
SwapBuffers(hDC)

Dim As Integer t = GetTickCount()
for i = 0 To ResX*ResY
pixel(i) = i + t
Next
loop
ExitProcess(0)
the code in c is this

Code: Select all

#include <windows.h>
#define ResX 256
#define ResY 192

int main(void) {
    // required data
    static int pixel[ResX*ResY];
    static BITMAPINFO bmi = {sizeof(BITMAPINFOHEADER),ResX,ResY,1,32};

    // window creation
    HWND hWnd = CreateWindowEx(0,"edit",0,(WS_OVERLAPPEDWINDOW | WS_SYSMENU) - (WS_THICKFRAME) | WS_VISIBLE,200,200,ResX,ResY,0,0,0,0);
    HDC hDC = GetDC(hWnd);
    ShowCursor(FALSE);

    // main loop
    for (MSG msg; msg.message != WM_KEYDOWN; PeekMessage(&msg,0,0,0,PM_REMOVE)) {
        // screen blitting
        int ScreenX = GetSystemMetrics(SM_CXSCREEN);
        int ScreenY = GetSystemMetrics(SM_CYSCREEN);
        StretchDIBits(hDC,0,0,ScreenX,ScreenY,0,0,ResX,ResY,pixel,&bmi,0,SRCCOPY);
        SwapBuffers(hDC);

        // pixel pushing
        int t = GetTickCount();
        for (int i = 0; i < ResX*ResY; i++) pixel[i] = i + t;
    }

    ExitProcess(0);
    return 0;
}
SARG
Posts: 1755
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Why doesn't this code compile?

Post by SARG »

There are several errors maybe when copying :

'dim as integer' missing variable name --> maybe 'i'
a line with only 'of' --> maybe do
'loop' without 'do' see line above

And change pixel by @pixel(0)

The program compiles and works but not sure it gives the expected result.

Code: Select all

#include "windows.bi"
#define ResX 256
#define ResY 192

Dim As MSG msg
Dim As Integer i
static As Integer pixel(ResX*ResY)
static As BITMAPINFO bmi = Type(sizeof(BITMAPINFOHEADER),ResX,ResY,1,32)
 
Dim As HWND hWnd = CreateWindowEx(0,"edit",0,(WS_OVERLAPPEDWINDOW Or WS_SYSMENU) - (WS_THICKFRAME) Or WS_VISIBLE,200,200,ResX,ResY,0,0,0,0)
Dim As HDC hDC = GetDC(hWnd)

do
PeekMessage(@msg,0,0,0,PM_REMOVE)
    Dim As Integer ScreenX = GetSystemMetrics(SM_CXSCREEN)
    Dim As Integer ScreenY = GetSystemMetrics(SM_CYSCREEN)
StretchDIBits(hDC,0,0,ScreenX,ScreenY,0,0,ResX,ResY,@pixel(0),@bmi,0,SRCCOPY)
SwapBuffers(hDC)

Dim As Integer t = GetTickCount()
for i = 0 To ResX*ResY
pixel(i) = i + t
Next
loop
ExitProcess(0)
myndgrrrrrl
Posts: 11
Joined: Feb 09, 2022 0:03

Re: Why doesn't this code compile?

Post by myndgrrrrrl »

Thank you for helping me.
Post Reply