PDA

View Full Version : Need help with dll and string pointers


lopez1de
10-07-2008, 10:04 AM
Hi,

I'm lost in C code again. I think this is really easy to answer, but after hours of testing I can't get it running.

I tried to read tags from mp3's with the free bass mod "TAGS". You will find the dll and the source here: http://www.un4seen.com/filez/3/tags.zip

I declared the following:

#define TAGS_VERSION 14;
#declare TAGS_Read "tags.dll" TAGS_Read 2 1;
#declare TAGS_GetVersion "tags.dll" TAGS_GetVersion 0 1;
#declare TAGS_GetLastErrorDesc "tags.dll" TAGS_GetLastErrorDesc 0 1;


All three functions are returning a LONG value.
TAGS_GetVersion - returns version (14)
TAGS_Read - returns the pointer to a string which is holding the returned tags
TAGS_GetLastErrorDesc - returns a pointer to the error message string

If I try to get a tag (song title) I get a pointer back.

BASS_Init( - 1, 44100, NULL, 0, NULL);
s2$ = BASS_StreamCreateFile(false, file$, 0, 0, NULL);
BASS_ChannelSetAttributes(s2$, -1, 90, -1);
BASS_ChannelPlay(s2$, true);

tags$ = TAGS_Read(s2$, "%TITL");


But I'm not able to convert tags$ to a readable string. My question is: How I'm able to get the string vom the returned pointer.
I tried to use
ShowMessage(@tags$);
and
ShowMessage(char(tags$));
but I only got exceptions.

Is someone able to help me out?

thanks in advance (again) ;)

PointOfLight
10-08-2008, 06:05 PM
The whole string-pointer thing is something I always struggle with for some reason, but would it work if you did the following:

&tags$ = TAGS_Read(s2$, "%TITL");
ShowMessage(tags$); //you may need the @ here

lopez1de
10-12-2008, 11:57 AM
Both don't work. This will return the pointer address:
&tags$ = TAGS_Read(s2$, "%TITL");
showmessage(tags$);

And this will return an access violation:
&tags$ = TAGS_Read(s2$, "%TITL");
showmessage(@tags$);

:(


Maybe there is a problem with ASCII/Unicode? Maybe it's the same thing as in this thread: http://forums.arianesoft.ca/showthread.php?t=1511

kornalius
10-28-2008, 01:39 PM
What does TAG$ variable contains? Does it look like a pointer?

Can you attach me the full PC code in this thread? I will look into it today.

lopez1de
10-28-2008, 03:03 PM
Thank you for replying. But I don't have the code with me. I try to recreate the code later in the hotel.

lopez1de
10-28-2008, 06:04 PM
Hi. Here is the code and the tags.dll. You will find the DLL on Bass Lib site also (Extensions).
The function should return a string, but it's returning a pointer which I'm not able to convert to string.

Thank you for helping me. I think it's only a problem with my c++ knowledge about pointers. :D

kornalius
10-29-2008, 12:31 PM
First thing I noticed, s2$ is NULL.

Are you sure BASS_StreamCreateFile creates the file properly? It doesn't look like it.

Edit: Nevermind, the file was not found, I got it to load and play the file now. Let's attack the string problem right now...

kornalius
10-29-2008, 03:42 PM
Got it. This is special problem caused with strings from another heap. The problem is that in C you cannot obtain the size of a pointer properly without walking the heaps of the process and that causes major slowdown. Strings coming from a .dll are contained within a different heap than the process heap and needs to be copied to PPL process using dup() before they can be used properly by PPL.

ShowMessage(dup(@tags$));

This will do the job perfectly for you. So first you need to transform the pointer value returned tags$ which is an integer value into a string value using @. Now PPL recognizes this value as a string, then you need to duplicate the content into the PPL process using dup(). It is a little tricky and might not be easy to understand.

I will add a new function to ease this process for version 1.53 called cptr().

lopez1de
10-29-2008, 03:48 PM
Nice to hear that. Well done. :)

Will test it later. We can now makw a new include for all. bass_tags.ppl or something. :D