Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Kitty Hello

Pages: [1] 2 3 ... 703
1
Code Snippets / Load data from memory
« on: 2021-Oct-14 »
I tell you a secret. GLBasic can load data from a memory buffer, as if it was a file. With the attached code, you can use the contents of a string to "read" it as a file. This should work for about everything. Sprites, sounds, binary files, ...

Code: (glbasic) [Select]



LOCAL mem$ = "Hello World"
LOCAL memlen = LEN(mem$)

LOCAL file$ = MemMakeFile$(mem$)

LOCAL text$
OPENFILE(1, file$, TRUE)
READSTR 1, text$, 64
CLOSEFILE 1
STDOUT text$ + "\n"
KEYWAIT

FUNCTION foo:
ENDFUNCTION

INLINE
extern "C" {int sprintf(char *str, const char *format, ...); }
ENDINLINE


FUNCTION MemMakeFile$: BYREF data$, nofBytes = -1
IF nofBytes < 0 THEN nofBytes = LEN(data$)
LOCAL url$
LOCAL hx$ = RIGHT$("0000000000000000" + HEX$(nofBytes), 8)
INLINE
void* address = &data_Str[0];
char buffer[64];
sprintf(buffer, "%x", address);

url_Str = CGStr("mem://") + hx_Str + CGStr(".") + CGStr(buffer);
ENDINLINE


RETURN url$
ENDFUNCTION

2
GLBasic - en / Re: Access to Buffer Data ?
« on: 2021-Sep-30 »
I ordered a Strato HiDrive account and will set up a Git repository. So we can use Git to act together. But, I failed to clone it. Maybe my work-configuration messes with the private account... I'll have to see.

3
GLBasic - en / Re: Access to Buffer Data ?
« on: 2021-Sep-30 »
Is it? Maybe we should include it as the default sound engine, then?

4
GLBasic - de / Re: Fehlermeldung bei DIM
« on: 2021-Sep-27 »
uni wurde als Integer erkannt, nicht als array. Schreib LOCAL uni[] davor.

5
GLBasic - en / Re: Access to Buffer Data ?
« on: 2021-Sep-27 »
I think we'd better go with "SOLOUD". That's a x-platform sound engine that does not suck (they say).

6
Didn't they re-design the workflow to make it easier for begginers a few yeas ago?

7
Off Topic / Re: Sir Clive
« on: 2021-Sep-27 »
Yes. RIP. We're getting old, friends...

8
Another try:
Code: (glbasic) [Select]
FUNCTION Get_Open_File_Name$:
INLINE
    char filename[ 2048 ] = "";
    // char filetitle[ 1024 ] = "";
    struct MYOFN : public tagOFNA{
    char extra_memory_just_to_be_safe[1024];
    };
    MYOFN ofn = {};

    ofn.lStructSize  = sizeof( tagOFNA );
    ofn.hwndOwner    = HWND(GLBASIC_HWND());  // If you have a window to center over, put its HANDLE here
    ofn.lpstrFilter  = "Jpg & Png File\0*.Jpg;*.png\0All Files(.)\0*.*\0\0\0\0\0\0\0\0\0\0";
    ofn.lpstrFile    = filename;
    ofn.nMaxFile     = 1000;
    char title[1024] = "Select a photo";
    ofn.lpstrTitle   = title;
    ofn.Flags        = OFN_DONTADDTORECENT | OFN_FILEMUSTEXIST;
    DGStr current = GETCURRENTDIR_Str();
    ofn.lpstrInitialDir   = current.c_str(); // Initial directory.
    ofn.lpstrFileTitle    = NULL;
    int ret=GetOpenFileNameA(&ofn);
    return DGStr(filename);
 ENDINLINE
ENDFUNCTION


9
Get the beta branch: I fixed it, didn't I?

10
Before the dialog opens? Or when you click "OK"?

11
Yikes. Can you debug in GLB and see what line it crashes? (Add some DEBUG() commands to find it in INLINE).

12
Good find. It was a signed/unsigned error checking the first bytes of the file. I'll prepare an update.

13
Doens't crash for me in debug mode. I think your problem is somewere else.

Code: (glbasic) [Select]


SYSTEMPOINTER TRUE
AUTOPAUSE FALSE

LOCAL a$ = Get_Open_File_Name$()
PRINT a$,0,0
SHOWSCREEN
MOUSEWAIT
END




// --------------------------------- //
// Project: Qedo
// Start: Saturday, June 26, 2021
// IDE Version: 16.793
FUNCTION foo:
ENDFUNCTION


INLINE
}
#define HINSTANCE W32HINSTANCE
#define HINSTANCE__ W32HINSTANCE__
#define HMODULE W32HMODULE
#undef LPSTR
#undef DECLARE_HANDLE
#undef LPCTSTR
#undef DWORD
#undef LPWSTR
#undef LPCWSTR
#define HWND W32HWND
#define HWND__ W32HWND__
#define HANDLE W32HANDLE
#undef MAX_PATH
#undef TCHAR
#define WIN32_LEAN_AND_MEAN
#define WinMain WinMain2

#include <windows.h>
#include <commdlg.h>
namespace __GLBASIC__ {
ENDINLINE
FUNCTION Get_Open_File_Name$:
INLINE
    char filename[ 1024] = "";
    // char filetitle[ 1024 ] = "";
    tagOFNA ofn;
    char extra_memory_just_to_be_safe[1024];

    for(int i=0; i<sizeof(tagOFNA); ++i) // ZeroMemory
    {
((char*)&ofn)[i] = 0;
    }

    ofn.lStructSize  = sizeof( ofn );
    ofn.hwndOwner    = HWND(GLBASIC_HWND());  // If you have a window to center over, put its HANDLE here
    ofn.lpstrFilter  = "Jpg & Png File\0*.Jpg;*.png\0All Files(.)\0*.*\0";
    ofn.lpstrFile    = filename;
    ofn.nMaxFile     = 1000;
    char title[1024] = "Select a photo";
    ofn.lpstrTitle   = title;
    ofn.Flags        = OFN_DONTADDTORECENT | OFN_FILEMUSTEXIST;
    ofn.lpstrInitialDir   = "."; // Initial directory.
    ofn.lpstrFileTitle    = NULL;
    int ret=GetOpenFileNameA(&ofn);
    return DGStr(filename);
 ENDINLINE
ENDFUNCTION

I fear, you're having a buffer overrun somewere else. These are hard to debug and find. Most likely in an INLINE block. Try to make a small as possible program, that crashes and zip it.

14
try this, maybe?

Code: (glbasic) [Select]

// --------------------------------- //
// Project: Qedo
// Start: Saturday, June 26, 2021
// IDE Version: 16.793

INLINE
}
#define HINSTANCE W32HINSTANCE
#define HINSTANCE__ W32HINSTANCE__
#define HMODULE W32HMODULE
#undef LPSTR
#undef DECLARE_HANDLE
#undef LPCTSTR
#undef DWORD
#undef LPWSTR
#undef LPCWSTR
#define HWND W32HWND
#define HWND__ W32HWND__
#define HANDLE W32HANDLE
#undef MAX_PATH
#undef TCHAR
#define WIN32_LEAN_AND_MEAN
#define WinMain WinMain2

#include <windows.h>
#include <commdlg.h>
namespace __GLBASIC__ {
ENDINLINE
FUNCTION Get_Open_File_Name$:
INLINE
    char filename[ 1024] = "";
    // char filetitle[ 1024 ] = "";
    tagOFNA ofn;
    char extra_memory_just_to_be_safe[1024];
   
    for(int i=0; i<sizeof(tagOFNA); ++i) // ZeroMemory
    {
((char*)&ofn)[i] = 0;
    }

    ofn.lStructSize  = sizeof( ofn );
    ofn.hwndOwner    = HWND(GLBASIC_HWND());  // If you have a window to center over, put its HANDLE here
    ofn.lpstrFilter  = "Jpg & Png File\0*.Jpg;*.png\0All Files(.)\0*.*\0";
    ofn.lpstrFile    = filename;
    ofn.nMaxFile     = 1000;
    char title[1024] = "Select a photo";
    ofn.lpstrTitle   = title;
    ofn.Flags        = OFN_DONTADDTORECENT | OFN_FILEMUSTEXIST;
    ofn.lpstrInitialDir   = "."; // Initial directory.
    ofn.lpstrFileTitle    = NULL;
    int ret=GetOpenFileNameA(&ofn);
    return DGStr(filename);
 ENDINLINE
ENDFUNCTION



See
https://www.glbasic.com/forum/index.php?topic=2129.0
and
https://docs.microsoft.com/en-us/windows/win32/api/commdlg/nf-commdlg-getopenfilenamea

Hints:
LPCTSTR - the 'C' stands for 'const'. If it's ommited, do NOT provide a hard coded string like "test", but a pointer to an allocated stack buffer.
I had problems with a wrong size of the struct once, so I added some extra bytes. Might not be a problem....
lpstrFileTitle    should be null.




15
can you zip me a tiny project?

Pages: [1] 2 3 ... 703