Results 1 to 9 of 9

Thread: [RESOLVED] VB6 Help with SDL2 Public Type SDL_Rect

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2020
    Location
    Brazil
    Posts
    11

    Resolved [RESOLVED] VB6 Help with SDL2 Public Type SDL_Rect

    Hi guys,

    I am working on SDL2 lib (Its crazy i know), and porting some functions.

    In the Wrapper DLL, we have this function:

    In C:
    Code:
    __stdcall int xSDL_BlitSurface(SDL_Surface* src, const SDL_Rect* srcrect, SDL_Surface* dst, SDL_Rect* dstrect) {
    	return SDL_BlitSurface(src, srcrect, dst, dstrect);
    }

    Code:
    Public Function BlitSurface(ByVal ssrc&, ByVal srcrect&, ByVal dst&, ByVal dstrect&) As Integer
        
        BlitSurface = p.CallFunc(DLLPath, retInteger, "xSDL_BlitSurface", ssrc, srcrect, dst, dstrect)
    
    End Function
    My problem now is the SDL_Rect.

    Where i can use this Type ?

    I am try this, but no success..

    Code:
    Private Type SDL_Rect
        x As Integer
        y As Integer
        w As Integer
        h As Integer
    End Type
    Any help,will welcome!

    Thanks in advance,

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,102

    Re: VB6 Help with SDL2 Public Type SDL_Rect

    Typically, outside of VB an Int is a Long. Try Long instead?

    Welcome to the forums
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,923

    Re: VB6 Help with SDL2 Public Type SDL_Rect

    And since it's a __stdcall export on the C-side, you can use a normal VB-Declare-Statement instead of p.CallFunc...
    (easier to define the UDT-passing in a Declare, if you have not much experience with the "DispCallFunc-API",
    where you should use VarPtr-wrapping for passing a struct as a pointer).

    HTH

    Olaf

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2020
    Location
    Brazil
    Posts
    11

    Re: VB6 Help with SDL2 Public Type SDL_Rect

    Quote Originally Posted by LaVolpe View Post
    Typically, outside of VB an Int is a Long. Try Long instead?

    Welcome to the forums
    Thanks LAVolpe,

    The problem is bigger here, see image.

    Name:  vb6-1.jpg
Views: 47
Size:  24.2 KB


    An see the IDE, which the functions:

    Name:  vb6-2.jpg
Views: 48
Size:  26.6 KB

    I Put the Type in a.bas module.
    Code:
    Public Type SDL_Rect
        x As Long
        y As Long
        w As Long
        h As Long
    End Type
    And nothing...

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2020
    Location
    Brazil
    Posts
    11

    Re: VB6 Help with SDL2 Public Type SDL_Rect

    Quote Originally Posted by Schmidt View Post
    And since it's a __stdcall export on the C-side, you can use a normal VB-Declare-Statement instead of p.CallFunc...
    (easier to define the UDT-passing in a Declare, if you have not much experience with the "DispCallFunc-API",
    where you should use VarPtr-wrapping for passing a struct as a pointer).

    HTH

    Olaf
    Thanks Olaf for the answer.

    But... stranger, the DLL calsl fails, with some type (retLong, retInteger), and using p.Func... its Work!?

    I will publish the code... wait a moment.

  6. #6

    Thread Starter
    New Member
    Join Date
    May 2020
    Location
    Brazil
    Posts
    11

    Re: VB6 Help with SDL2 Public Type SDL_Rect

    Quote Originally Posted by Schmidt View Post
    And since it's a __stdcall export on the C-side, you can use a normal VB-Declare-Statement instead of p.CallFunc...
    (easier to define the UDT-passing in a Declare, if you have not much experience with the "DispCallFunc-API",
    where you should use VarPtr-wrapping for passing a struct as a pointer).

    HTH

    Olaf
    Here is the code and DLLs.

    https://drive.google.com/open?id=1d2...uvrlYkQYR-7NVl

    Cant upload to the forum.

    Thanks!
    Last edited by xmaxmex; May 10th, 2020 at 07:42 PM.

  7. #7

    Thread Starter
    New Member
    Join Date
    May 2020
    Location
    Brazil
    Posts
    11

    Re: VB6 Help with SDL2 Public Type SDL_Rect

    Quote Originally Posted by Schmidt View Post
    And since it's a __stdcall export on the C-side, you can use a normal VB-Declare-Statement instead of p.CallFunc...
    (easier to define the UDT-passing in a Declare, if you have not much experience with the "DispCallFunc-API",
    where you should use VarPtr-wrapping for passing a struct as a pointer).

    HTH

    Olaf
    Well, exist some docs about that?

  8. #8
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,102

    Re: VB6 Help with SDL2 Public Type SDL_Rect

    The problem is bigger here, see image.
    Your original function was more correct when you were passing the rects as Longs. I am assuming you were passing them like: ByVal VarPtr(mySDL_Rect). Continue doing that. Passing pointers when pointers parameters are ByRef gets past lots of problems and allows you to call the DLL directly vs using DispCallFunc, as Schmidt was suggesting.

    When structures are passed by ref, (i.e., from your documentation: SDL_Rect* srcrect, then * = Pointer)
    Last edited by LaVolpe; May 10th, 2020 at 09:47 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  9. #9

    Thread Starter
    New Member
    Join Date
    May 2020
    Location
    Brazil
    Posts
    11

    Re: VB6 Help with SDL2 Public Type SDL_Rect

    Quote Originally Posted by LaVolpe View Post
    Your original function was more correct when you were passing the rects as Longs. I am assuming you were passing them like: ByVal VarPtr(mySDL_Rect). Continue doing that. Passing pointers when pointers parameters are ByRef gets past lots of problems and allows you to call the DLL directly vs using DispCallFunc, as Schmidt was suggesting.

    When structures are passed by ref, (i.e., from your documentation: SDL_Rect* srcrect, then * = Pointer)
    Very Thanks LaVolpe and Schmidt,

    The final Function:

    Code:
    Public Function BlitSurface(ssrc As Long, srcrect As Long, dst As Long, dstrect As Long) As Integer
       
        BlitSurface = p.CallFunc(DLLPath, retInteger, "xSDL_BlitSurface", ssrc, srcrect, dst, dstrect)
    
    End Function

    And sample code:
    Code:
    Public Type SDL_Rect
        x As Long
        y As Long
        w As Long
        h As Long
    End Type
    
    ...
    
        Dim srcrect As SDL_Rect
        Dim dstrect As SDL_Rect
            
        srcrect.x = 0
        srcrect.y = 0
        srcrect.h = 10
        srcrect.w = 10
            
        dstrect.x = 7
        dstrect.y = 7
        dstrect.h = 20
        dstrect.w = 20
        
        SDL2.BlitSurface surface, 0, screen, VarPtr(dstrect)    
        SDL2.UpdateWindowSurface window
        
        Debug.Print "zaraki img.."
        
        SDL2.Delay 4000
            
        dstrect.x = 80
        dstrect.y = 20
        
        SDL2.BlitSurface surface, 0, screen, VarPtr(dstrect)
        SDL2.UpdateWindowSurface window
        
        SDL2.Delay 4000
    Thanks to All.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width