C, resource files and pointers conversion to PB

Windows specific forum
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by SimpleMind.

Hi,

I have some c code that, after compilation into a Dll, can be hooked in a program. What I want is try to translate this c code in PB.

I read now for version PB3.4, no more '_' when creating a DLL, so this creates some possibilities.

The problem I have is that this c code heavily uses pointer and structures referenced by pointers and the names of the functions must exact match. The code also uses recource files .RC. Can somebody give me a hint for translation or maybe someone has info as Ccode = PBcode and how to code resources in PB.


SimpleMind,

KISS (keep it simple and smart). Don't forget to laugh.

- Registered PureBasic Coder. -
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by SoulTaker.

Hi SimpleMind,

I'am currentily work on a Resource Editor for PureBasic Ver 3.50 hopefully will include resources.

I currentily have PureBasic Procedures for opening the resource DLL, Loading and Displaying Bitmaps to a PureBasic Window.

I plan on this to also have it to build windows and dialogs and write out the code for it.
I'm writing the Procedures now for the Grab Handles to resize windows, dialogs and Gadgets.

So if i can help you out let me know.


Abit BD7-II Raid P4 1.9 gHz 384 Ram Xtasy GFroce 3 TI 200 CD-RW DirectX 9.0 Beta 3 Sound Blaster Live! XP Pro, Registered PureBasic User Version 3.40 For Windows.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by SimpleMind.

Hi SoulTaker,
Originally posted by SoulTaker

Hi SimpleMind,

I'am currentily work on a Resource Editor for PureBasic Ver 3.50 hopefully will include resources.

I currentily have PureBasic Procedures for opening the resource DLL, Loading and Displaying Bitmaps to a PureBasic Window.

I plan on this to also have it to build windows and dialogs and write out the code for it.
I'm writing the Procedures now for the Grab Handles to resize windows, dialogs and Gadgets.

So if i can help you out let me know.
Thanks for your offer to help and I'm curious how you handle this resource stuff.
At this moment I'm (trying ) to translating some c code to PB. I'm so far that I can place and understand some of the code parts in C (I'm using LCC from Jacob Navia and he has a lot of very good information). A tedious process because I haven't programmed in C for years. A part of the problem is that the C code uses some recources to put a simple dialog box on the screen. A second problem is that I have no clue how to translate some constructions from C to PB. Simple pointers isn't the problem but pointer to functions that returns arrays of pointers to chars is a little bit to much for my simple mind :), I just have to grow in the code.

SimpleMind,

KISS (keep it simple and smart). Don't forget to laugh.

- Registered PureBasic Coder. -
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by SoulTaker.

Hi SimpleMind,

Check the Link out below its on PureBasic Pointers, I had trouble at first also but the kind people here helped me out alot. I would also post in the fourm topic beginners, the people here are very nice and wonderful.

http://www.reelmediaproductions.com/pb/ ... nters.html

You need to use the windows resource API Functions to use your resources.

for your Dialog you will need to use one of the windows DialogBox API Functions.


Abit BD7-II Raid P4 1.9 gHz 384 Ram Xtasy GFroce 3 TI 200 CD-RW DirectX 9.0 Beta 3 Sound Blaster Live! XP Pro, Registered PureBasic User Version 3.40 For Windows.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by SoulTaker.

Here is some of the Procedures that I have written so far.
NOTE: The _ is used in the Windows API Functions...
API FunctionName_(Parameters).

Hopes this helps.

;==============================================================================
;== Procedures For Accessing A Resource DLL In PureBasic.
;==============================================================================

;== Declare Our Resource Procedure's Helps!
Declare RS_LoadResDLL(FileName$)
Declare RS_LoadResBitmap(hDll, hBmp$)
Declare RS_DrawResBitmap (hWnd, hBmp, xStart, yStart)

;==============================================================================
;== Procedure : RS_LoadResDLL(FileName$)
;==
;== Description: Load's An Applications Resource DLL.
;== Parameters : FileName$ - The Filename Of The Resource DLL To Load.
;== Returns : A Handle To The Resource DLL.
;==============================================================================
Procedure RS_LoadResDLL(FileName$)

ProcedureReturn LoadLibrary_(FileName$)

EndProcedure

;==============================================================================
;== Procedure : RS_LoadResBitmap(hDLL, hBmp$)
;==
;== Description: Load's An Applications Resource Bitmap.
;== Parameters : hDLL - The Handle Returned From LoadResDLL Procedure.
;== Returns : A Handle To The Resource Bitmap If Loaded.
;==============================================================================
Procedure RS_LoadResBitmap(hDLL, hBmp$)

ProcedureReturn LoadBitmap_(hDLL, hBmp$)

;hbm = LoadBitmap_(hDll, BmpID) ;"bitmap1");

EndProcedure

;==============================================================================
;== Procedure : RS_DrawResBitmap(hWnd, hBmp, xStart, yStart)
;==
;== Description: Draws An Applications Resource Bitmap To A Window Etc.
;== Parameters : hWnd - The Handle To A PureBasic Winodw IE: WindowID().
;== hBmp - Handle Returned From RS_LoadResBitmap.
;== xStart - x Position Of Window To Start Drawing.
;== yStart - y Position Of Window To Start Drawing.
;==============================================================================
Procedure RS_DrawResBitmap (hWnd, hBmp, xStart, yStart)

bm.BITMAP ;== Bitmap Structure.

WinDC.l ;== Windows DC.
MemDC.l ;== Memory DC.

;== Get The PureBasic Windows DC.
WinDc = GetDC_(hWnd)

;== Create A Memory DC For The Window To Draw Into.
MemDC = CreateCompatibleDC_(WinDC)

;== Select The Bitmap Into The Memory DC And Get The Mode.
SelectObject_(MemDC, hBmp)
SetMapMode_(MemDC, GetMapMode_(WinDC))

;== Get The Bitmap Object.
GetObject_(hBmp, SizeOf(BITMAP), @bm)

;== BitBlt It To The Windows DC From The Memory DC.
BitBlt_(WinDC, xStart, yStart, @bm\bmWidth, @bm\bmHeight, MemDC, 0, 0, #SRCCOPY)

;== Clean Up By Releasing And Deleting Our Objects.
ReleaseDC_(hWnd, WinDC)
DeleteDC_(MemDC)

DeleteObject_(WinDc)
DeleteObject_(hBmp)

EndProcedure


Abit BD7-II Raid P4 1.9 gHz 384 Ram Xtasy GFroce 3 TI 200 CD-RW DirectX 9.0 Beta 3 Sound Blaster Live! XP Pro, Registered PureBasic User Version 3.40 For Windows.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by SimpleMind.

Thanks, Soultaker. The pointer info you gave me helped me a lot, it gives a clear look at it. About your code: I'll look forward when you are ready with it. I'll can learn a lot of it.

SimpleMind,

KISS (keep it simple and smart). Don't forget to laugh.

- Registered PureBasic Coder. -
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by SoulTaker.

Thank yo SimpleMind,

Sorry if i dont get right back to you i work 3nd shift here in the USA 2:00 pm till 10:30 pm.

Well if it was'nt for a lot of help from the wonderfull people here I would still be stuck code.
I do have to say Thank yo to all of them.

Right now I'm designing the dragging and grab handles for dragging PureBasic gadets and sizing them. I'm waiting on ver 3.50 for now on the resource stuff cause Fred is going to add resource files to it. I'll be on vacation again on the 9 - 18 in Nov so I'll have lots of time to work on it some more.

Also I'm Desiging my Web Site to help out new commers to PureBasic.



Abit BD7-II Raid P4 1.9 gHz 384 Ram Xtasy GFroce 3 TI 200 CD-RW DirectX 9.0 Beta 3 Sound Blaster Live! XP Pro, Registered PureBasic User Version 3.40 For Windows.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by SimpleMind.

Hi, SoulTaker have a nice vacation and enjoy coding. I'll have a job to do in Filemaker and set aside this PB-leisure for some days. Meanwhile I follow the discussions on a low activity level.

SimpleMind,

Whatever you can do or hope you can do, do it.
There lies ingenuity, power and magic in audacity.
Johan Wolfgang von Goethe

- Registered PureBasic Coder. -
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by SoulTaker.

hopefully I'll have some nice stuff done by the end of my vacation!


Abit BD7-II Raid P4 1.9 gHz 384 Ram Xtasy GFroce 3 TI 200 CD-RW DirectX 9.0 Beta 3 Sound Blaster Live! XP Pro, Registered PureBasic User Version 3.40 For Windows.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

SoulTaker:
> I'm waiting on ver 3.50 for now on the resource stuff
> cause Fred is going to add resource files to it.

Fred never said he is adding the resource stuff in v3.50.
He changed the compiler v3.50 to use FASM as the assembler
and with FASM it should be little bit easier to add resources
(but thats not 100% sure with the way PureBasic works).

Maybe Fred can take a look at it for 3.50 or 3.60 or ...
but until now he didnt say he will add it to 3.50.

cya,
...Danilo

(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by SoulTaker.

Thanks Danilo,

Must have misunderstood him but i can still do it with the DLL, if i code it write shouldn't have to change much.



Abit BD7-II Raid P4 1.9 gHz 384 Ram Xtasy GFroce 3 TI 200 CD-RW DirectX 9.0 Beta 3 Sound Blaster Live! XP Pro, Registered PureBasic User Version 3.40 For Windows.
Post Reply