Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dynamic Libraries (Windows)
#28
Pete,  YOURE OLD MAN! Accept it! (Also if you talk to Ted, say hi from me!)

Now, i can do it one of two ways but MY way is the best and easiest....so the first way (QB64 only code) aint gonna happen!

From me telling Googles Ai the premise and then ages making tweaks and telling it to not be so smart as Im dumb here's and idea...

FOR YOU ill make anything if i can or go for Aspirins after 2 days of failiure! 

TELL ME how youd want it, the requirements, what does QB64 need to see? (load, play, pause, volume etc...) and then bish bash bosh and you'll owe me a +1

Me, my idea is to allow for any number of AVIs to be loaded, each ones state stored internally and then each AVI referenced via index. QB64 will only ever need the index, when loading a new avi the index returned is that file and then all concurrent commands take said index and do their thing!

John

*NOTE the below is me chatting with google

To implement the QB_AVI system, we will use a C++ structure (UDT) to track each video’s state and store them in a std::vector. The C++ layer will return a simple index to QB64.
1. The C++ Core (QB_AVI.cpp)
This code manages the video metadata. We use mciSendCommand for speed and efficiency.
cpp
#include <windows.h>
#include <mmsystem.h>
#include <vector>
#include <string>

#define QB_EXPORT extern "C" __declspec(dllexport)

struct QB_AVI_STATE {
    UINT deviceID;
    long start;
    long current;
    long end;
    int vol; // 0-1000
};

std::vector<QB_AVI_STATE> AVIs;

QB_EXPORT int QB_AVI_Load(const char* filename) {
    MCI_OPEN_PARMS openParms = {0};
    openParms.lpstrDeviceType = "avivideo";
    openParms.lpstrElementName = filename;

    if (mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD_PTR)&openParms) == 0) {
        QB_AVI_STATE vid;
        vid.deviceID = openParms.wDeviceID;
       
        // Get length in frames
        MCI_STATUS_PARMS status = {0};
        status.dwItem = MCI_STATUS_LENGTH;
        mciSendCommand(vid.deviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&status);
       
        vid.start = 0;
        vid.end = status.dwReturn;
        vid.current = 0;
        vid.vol = 500;
       
        AVIs.push_back(vid);
        return (int)AVIs.size() - 1;
    }
    return -1;
}

QB_EXPORT void QB_AVI_Render(int index, HWND hwnd, int x, int y, int w, int h) {
    if (index < 0 || index >= AVIs.size()) return;
    QB_AVI_STATE &v = AVIs[index];

    // Bind to window
    MCI_DGV_WINDOW_PARMS win = {0};
    win.hWnd = hwnd;
    mciSendCommand(v.deviceID, MCI_WINDOW, MCI_DGV_WINDOW_HWND, (DWORD_PTR)&win);

    // Set destination rectangle
    MCI_DGV_PUT_PARMS put = {0};
    put.rc = { (LONG)x, (LONG)y, (LONG)(x + w), (LONG)(y + h) };
    mciSendCommand(v.deviceID, MCI_PUT, MCI_DGV_PUT_DESTINATION | MCI_DGV_RECT, (DWORD_PTR)&put);

    // Play from current
    MCI_PLAY_PARMS play = {0};
    mciSendCommand(v.deviceID, MCI_PLAY, 0, (DWORD_PTR)&play);
}

QB_EXPORT long QB_AVI_GetPos(int index) {
    if (index < 0 || index >= AVIs.size()) return 0;
    MCI_STATUS_PARMS status = {0};
    status.dwItem = MCI_STATUS_POSITION;
    mciSendCommand(AVIs[index].deviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&status);
    return status.dwReturn;
}
Use code with caution.

2. QB64 Library Declaration
In QB64, you link the compiled DLL. Note the use of _OFFSET for the window handle (essential for 64-bit compatibility in 2025).
vb
DECLARE DYNAMIC LIBRARY "QB_AVI"
    FUNCTION QB_AVI_Load% (filename AS STRING)
    SUB QB_AVI_Render (BYVAL index AS LONG, BYVAL hwnd AS _OFFSET, BYVAL x AS LONG, BYVAL y AS LONG, BYVAL w AS LONG, BYVAL h AS LONG)
    FUNCTION QB_AVI_GetPos& (BYVAL index AS LONG)
END DECLARE

' Usage
SCREEN _NEWIMAGE(1280, 720, 32)
vIndex% = QB_AVI_Load("test.avi" + CHR$(0))

IF vIndex% >= 0 THEN
    QB_AVI_Render vIndex%, _WINDOWHANDLE, 0, 0, 1280, 720
    DO
        LOCATE 1, 1: PRINT "Current Frame:"; QB_AVI_GetPos(vIndex%)
        _LIMIT 60
    LOOP UNTIL _KEYHIT = 27
END IF
Use code with caution.

Why this is a "Cake Walk"
Vector Management: QB64 only passes a LONG index. You can load 100 AVIs and the C++ side manages the memory via the vector.
UDT Logic: Properties like start, end, and vol are stored in the C++ struct. You can add getters/setters easily (e.g., QB_AVI_SetVol).
Handle Safety: By using _WINDOWHANDLE, the video is clipped and rendered directly by the Windows display driver into your QB64 workspace.


SIDE NOTE : From my current DEV ive learned that there is NEXT TO NOTHING we cant add to QB64 using C/C++ wrappers and declare lib...SO IF ANYONE WANTS ANYTHING else like this...ask and i will deliver or tell you im too dumb to do it!

Second note @ DEVS : ADD A _Screen function...I KNOW that GL 4.6, DX 9-11/12 and VULKAN are not HARD to implement. In fact id wager that at least for Gl no more than 5 or 6 lines of code need to be added to allow Qb64 to use all GL functionality! (Not bragging here but Galleon used SFML to demo Declare library and GL. He was VERY against adding GL to QB64 until i showed my work, begged and pleaded and eventually he made the work around we have today) That was 2011 and even then it was OLD! My new GDK allows for any number of screens in any render mode, GL DX etc...so if you dont add it I will!

John
Reply


Messages In This Thread
Dynamic Libraries (Windows) - by Petr - 12-08-2025, 06:48 PM
RE: Dynamic Libraries - by Petr - 12-08-2025, 07:12 PM
RE: Dynamic Libraries - by Petr - 12-08-2025, 07:52 PM
RE: Dynamic Libraries - by Jack - 12-08-2025, 08:41 PM
RE: Dynamic Libraries - by Petr - 12-09-2025, 07:21 PM
RE: Dynamic Libraries - by Petr - 12-11-2025, 04:19 PM
RE: Dynamic Libraries - by Petr - 12-12-2025, 10:00 PM
RE: Dynamic Libraries - by Petr - 12-13-2025, 05:56 PM
RE: Dynamic Libraries - by 2112 - 12-13-2025, 07:06 PM
RE: Dynamic Libraries - by ahenry3068 - 12-13-2025, 07:47 PM
RE: Dynamic Libraries - by Petr - 12-13-2025, 07:41 PM
RE: Dynamic Libraries - by 2112 - 12-13-2025, 08:23 PM
RE: Dynamic Libraries - by Petr - 12-13-2025, 08:36 PM
RE: Dynamic Libraries - by Petr - 12-13-2025, 09:03 PM
RE: Dynamic Libraries - by ahenry3068 - 12-13-2025, 11:16 PM
RE: Dynamic Libraries - by Petr - 12-14-2025, 12:15 AM
RE: Dynamic Libraries - by Petr - 12-15-2025, 08:22 AM
RE: Dynamic Libraries (Windows) - by Petr - 12-15-2025, 06:30 PM
RE: Dynamic Libraries (Windows) - by Mad Axeman - 12-19-2025, 02:37 PM
RE: Dynamic Libraries (Windows) - by Pete - 12-18-2025, 07:45 PM
RE: Dynamic Libraries (Windows) - by Steffan-68 - 12-18-2025, 08:31 PM
RE: Dynamic Libraries (Windows) - by Pete - 12-18-2025, 08:55 PM
RE: Dynamic Libraries (Windows) - by Steffan-68 - 12-18-2025, 09:48 PM
RE: Dynamic Libraries (Windows) - by Petr - 12-18-2025, 09:32 PM
RE: Dynamic Libraries (Windows) - by Pete - 12-18-2025, 11:53 PM
RE: Dynamic Libraries (Windows) - by Pete - 12-19-2025, 06:40 AM
RE: Dynamic Libraries (Windows) - by Unseen Machine - 12-19-2025, 02:39 PM
RE: Dynamic Libraries (Windows) - by Petr - 12-19-2025, 03:08 PM
RE: Dynamic Libraries (Windows) - by Petr - 12-19-2025, 10:35 PM
RE: Dynamic Libraries (Windows) - by Petr - 12-19-2025, 10:54 PM
RE: Dynamic Libraries (Windows) - by Petr - 12-19-2025, 11:20 PM
RE: Dynamic Libraries (Windows) - by Pete - 12-19-2025, 11:37 PM
RE: Dynamic Libraries (Windows) - by Petr - 12-20-2025, 10:22 PM
RE: Dynamic Libraries (Windows) - by SMcNeill - 12-20-2025, 11:03 PM
RE: Dynamic Libraries (Windows) - by Petr - 12-21-2025, 05:40 PM
RE: Dynamic Libraries (Windows) - by Petr - 12-22-2025, 08:23 PM
RE: Dynamic Libraries (Windows) - by Petr - 12-23-2025, 09:06 AM
RE: Dynamic Libraries (Windows) - by Petr - 12-24-2025, 09:54 PM
RE: Dynamic Libraries (Windows) - by Petr - 12-25-2025, 10:02 AM
RE: Dynamic Libraries (Windows) - by Petr - 12-26-2025, 11:14 PM
RE: Dynamic Libraries (Windows) - by Petr - 12-27-2025, 01:35 PM
RE: Dynamic Libraries (Windows) - by MasterGy - 12-27-2025, 07:23 PM
RE: Dynamic Libraries (Windows) - by Petr - 01-07-2026, 06:31 PM
RE: Dynamic Libraries (Windows) - by Petr - 01-07-2026, 09:13 PM
RE: Dynamic Libraries (Windows) - by Petr - 02-24-2026, 06:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Dynamic Libraries (Linux) Petr 19 1,224 12-29-2025, 09:52 PM
Last Post: Petr

Forum Jump:


Users browsing this thread: 1 Guest(s)