Problems - LoadSprite in a DLL

Advanced game related topics
User avatar
Epyx
User
User
Posts: 44
Joined: Fri May 09, 2003 10:54 am
Location: Germany
Contact:

Problems - LoadSprite in a DLL

Post by Epyx »

Hi, i try to code a Tile Based Scrolling Engine for Pure Basic. I want to put the whole code in a DLL. But i have some Problems to load a Sprite into my DLL,

I use the following code to load the Sprite, the Init stuff was done before (SpriteInit() aso.)

Code: Select all

ProcedureDLL.w Map_LoadTiles(FileName.s)  
;#### Die benutzen Tiles in ein Sprite laden ###

Map_LoadTiles.w= LoadSprite(100, FileName.s) 

ProcedureReturn Map_LoadTiles.w
EndProcedure

I call the DLL with the exact Path to the GFX file, but this returns always a 0 . The same code with LoadImage works correctly and Returns <> 0

Code: Select all

ProcedureDLL.w Map_LoadTiles(FileName.s)  
;#### Die benutzen Tiles in ein Sprite laden ###

Map_LoadTiles.w= LoadImage(100, FileName.s) 

ProcedureReturn Map_LoadTiles.w
EndProcedure

Why is this so, please help me and Sorry for my bad english.
Greets Epyx
Fred
Administrator
Administrator
Posts: 16687
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Why do you want to put the code in a DLL exactly ?
User avatar
Epyx
User
User
Posts: 44
Joined: Fri May 09, 2003 10:54 am
Location: Germany
Contact:

Post by Epyx »

?? what a question ??
Hmm why not, its my first dll and i want to write a DLL.
I had written a Map Editor before 3-4 Years (Visual Basic) and i tried to write loader routines for some kind of basic languages.
Okay now i try it to do with Pure Basic, and after my DLL i will code an new and better version of my Map Editor also with Pure Basic, i love PB.
Hmm my English ist horrible i know, i cant explain it all in english.

But back to my question, is it possible to load Sprites in a DLL.
if YES please show me the way to do that,
Fred
Administrator
Administrator
Posts: 16687
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Remember you can't use the PB high level functions in a DLL to use with another programming langage (unless if if for your own needs only).

About the sprites in DLL, it should be possible, be sure you call InitSprite() in the DLL init routine.
User avatar
Epyx
User
User
Posts: 44
Joined: Fri May 09, 2003 10:54 am
Location: Germany
Contact:

Post by Epyx »

Remember you can't use the PB high level functions in a DLL to use with another programming langage (unless if if for your own needs only).
I dont want to do this... the loader is only for PB

Ive Called InitSprite() in a own Map_init Procedure but i cant still load this Sprite file. Without a initSprite before stops the programm with a error (10599075) at the LoadSprite Command!!

After my Init Procedure (InitSprite() also) works all okay, but the Sprite File cant be loaded, Return Code is 0. When i change the LoadSprite command to LoadImage und start again Returns a number <> 0.

I need this Sprite File for the Tiles of a Map, i want to write a function that draws a Map area on a Screen.
Fred
Administrator
Administrator
Posts: 16687
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

You have to call OpenScreen() or OpenWindowedScreen() before loading a sprite, right ?
User avatar
Epyx
User
User
Posts: 44
Joined: Fri May 09, 2003 10:54 am
Location: Germany
Contact:

Post by Epyx »

Yes, but i open the Screen in my Client PB source who also called my DLL.
I have written a little test DLL and a test client proggy, the problem is also here.

Download all files of my Test DLL


This is my Test DLL
ProcedureDLL Map_Init()

Init1=InitSprite()

UseJPEGImageDecoder()
#Sprite_Nummer=59999

Global Map_Ed$, Map_EdV$, Map_Tile_Size, Map_SizeX, Map_SizeY, Map_ItemLayer
Global Map_TileName$, Map_Title$, Map_Author$, Map_Comment$
ProcedureReturn #TRUE

EndProcedure


ProcedureDLL.w Map_LoadTiles(FileName.s)

Map_LoadTiles.w= LoadSprite(#Sprite_Nummer, FileName.s,0)
ProcedureReturn Map_LoadTiles.w
EndProcedure


ProcedureDLL Map_Sprite()
DisplaySprite(#Sprite_Nummer,0,0)

EndProcedure

And here my Client Proggy....

X= InitSprite()
X= InitKeyboard()

hWnd=OpenWindow(0,0,0,640,480,#PB_Window_SystemMenu|#PB_Window_WindowCentered,"Show Map Settings")
x=OpenWindowedScreen(hWnd,0,0,640,480,0,0,0)
SetFrameRate(100)


UseJPEGImageDecoder()

; Open my test Lib
x=OpenLibrary(1,"test.dll")

; Call the Init routines, also InitSprite in the DLL
x=CallFunction(1,"Map_Init")

; try to load the Sprite,
x=CallFunction(1,"Map_LoadTiles","c:\space.jpg")


MessageRequester("Test - Sprite Handle",Str(x), #MB_ICONINFORMATION)




; Display Sprite, on the Screen
ClearScreen(0,0,0)
If x<> 0 : CallFunction(1,"Map_Sprite") : EndIf


; nothing to do, only loop and loop and loop and loop....
Repeat
ExamineKeyboard() : Taste = KeyboardPushed(#PB_Key_Escape)

Event = WindowEvent()
Select Event
Case #PB_Event_CloseWindow
End
EndSelect




FlipBuffers()
Until (Taste<>0)

End
Fred
Administrator
Administrator
Posts: 16687
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

It will not work, as it doesn't share the same memory space. So the DLL thinks there is no screen opened and the LoadSprite() fails. You can't mix the commands like that..
Post Reply