News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Convert image id from text file to resource id

Started by devilhorse, November 16, 2008, 12:25:13 AM

Previous topic - Next topic

devilhorse

I have been assigned a task to write an employee management program that displays the photo of the employee when the secretary types in the employee name and presses the search button. The names of the employees are stored in a comma de-limited file as follows:
lastname,firstname,middlename,imageidnum

I have successfully parsed the text file and extracted the value of the imageidnum and stored it in a buffer for use in the SetImage function.

The problem is when I call SetPicture and pass the buffer contents as the second argument, the image does not load into the Image control.

If I hard-code an imageidnum the image corresponding to this imageidnum loads into the Image control and displays properly.

Example Code

Below is an example of how the employee is stored in the text file.
Doe,John,Dead,120

.Data ?
idBuffer db 10 Dup(?)
hImageControl DD ?



.Code

...At this point the imageidnum 120 of John Dead Doe has been extracted from the text file and stored in idBuffer

...Now let us pass the idBuffer contents to SetPicture function.
Invoke SetPicture, hImageControl1, addr idBuffer

KaBoom!#@* No image displays.

I have tried using the conversion procedures found in Masm32 Library: atol, atodw etc.

I called atol after storing 120 in the idBuffer and to my surprise it showed the letter 'y'.

What am I doing wrong? What procedure should I call to convert for example the text 152 to the number 152 for use in the SetPicture function instead of having to hard-code the number?

Mark Jones

Hello, when "imageidnum 120 of John Dead Doe has been extracted from the text file and stored in idBuffer", can this value be displayed correctly by using invoke MessageBox,0,addr idBuffer,0,ID_OK ? If so and this displays "120", then you know the ASCII string data is being read into idBuffer correctly (and the problem must be elsewhere.) In that case, study ATODW more closely -- hint: it has an unusual parameter order.

I looked for "SetImage" and "SetPicture" but could find no matching native API's -- are these functions or macros present in some other lib? If so, consider if supplying them with a valid image "handle" at assemble-time is somehow conditionally affecting assembly.
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

devilhorse

Yes, when imageidnum 120 of John Dead Doe has been extracted from the text file and stored in idBuffer it correctly displays "120" when invoking MessageBox,0,addr idBuffer,0,ID_OK.

SetPicture is an Easy Code Method. Below is the text from the Easy Code help file.

SetPicture method


Available for Window, MDIWindow, DialogBox, Button, Picture and Image objects.

Prototype

SetPicture Proto hWnd:HWND, hPicture:DWord

Syntax

Invoke SetPicture, hWnd, hPicture

Function

Sets the Picture property for an object (see REMARKS).

Parameters

hWnd

Handle to the object.

hPicture

A DWord value specifying the new picture for the object.

Return value

Eax returns TRUE if succesful, or FALSE if not.


REMARKS: The hPicture parameter may be an existing resource ID or the handle to an image (bitmap, icon or cursor). First, Easy Code tries to load it as a resource (only if it is less than 65536) and, if it fails, then it is processed as a handle.

The image for John Doe has been added to the Easy Code project as a resource with the id of 120.

Since there ia an existing resource id and the text stored in idBuffer displays correctly, I cannot figure out why the image is not loaded unbless the number 120 is hard-coded.