String pointer
Blitz3D Forums/Blitz3D Beginners Area/String pointer
| ||
Is there a way to get the pointer to a string. I want to pass a string to a DLL but it only accept a pointer to the string. |
| ||
Yes, you can create a bank and poke the string into it. The string should end with a chr$(0) :bank = CreateBank(255) s$ = "hello world" + chr$(0) for i = 1 to len(s$) PokeByte bank, i-1, asc(mid$(s$,i,1)) next //--->send bank to dll here FreeBank bank |
| ||
Thanks i will try it. Another question. If have a example program that use a '*' gehind the name. I can not find the explenation of it. I assume thats a pointer. E.g. Pointer* = CreatBank(150) |
| ||
I only saw this "*" sign in .decls files. In that case, that is a pointer. When I tried in B3D, it returned an "end of line expected" error. |
| ||
Your right. Thats where i saw it to. So the "*" is a pointer. That means that if i use a membank and the adres i get back is a pointer. correct me if iam wrong. I try to understand it compleetly. Sorry for that many questions. |
| ||
If the dll function is expecting a memory-adress (eg. to move data to it, or to read data from it) as a parameter, and you want it to work with a blitz bank, then you have to use the *. |
| ||
Right but if i use the * at a variable i got the warning expeted end of file. So how come the * in use. |
| ||
The asterix is only allowed in a .decls file. In Blitz, you can use a bank. The bank variable is an integer pointer to the bank's memory. bank = createbank(255) ;now the variable 'bank' holds an integer pointer to the 255 bytes of allocated memory ;to read/write the content of this memory, use Peek/PokeByte Some DLL calls return string pointers (something like LPSTR?), for example to enumerate device names. To read them, first create a bank, then call the function with the bank as a parameter, then use Chr$(PeekByte()) to read the string from the bank into Blitz. I believe, in these situations, that the final character of the string is a Chr$(0) as well. |
| ||
Thanks now i get thew hole idea behind the pointer part. See if i can use it to work for me. |
| ||
Just wondering, what use does this have? I don't know a lot about memory manipulation... |
| ||
I have a I/O muodule and i want sending text to it. The communication DLL for this can handle only pointers. So i have to send pointer for the screen location and characters. I am busy with it and for now i get only tiny dot on the display. But that is more then i have 3 days ago. The conversion in the program is not working right but that is matters of days befor i found it. |
| ||
The advantage of sending pointers, I think, is that you don't need to pass a large structure to the .dll, only a single integer that points to this structure. You could maybe use a single bank. First, pokeint the two coordinates for the screen position, then pokebyte the string into the bank. Then, call the function with the parameters bank, bank + 4, and bank + 8. If you still have trouble getting the function to work, maybe you could post the dll/decls ? |
| ||
It's not only for your own DLLs, but also for the windows dlls. Many Windows API commands ask for such an adress. They tell you a description of the data block structure they need to transmit data to it (in the API docs), and you have to make this bank ready. After the dll used to write to this bank you'll be able to peek certain information from it. I used this not so long ago to make a windows movie dll transfer a certain frame of an AVI to a blitz bank (see code archives) The handle of the bank (eg: bankhandle=createbank(256)) is somehow related to the REAL physical adress of the banks memory in the Ram. I used to post an example on how to use a bank as an image in the archives that explains this relation. Sometimes you need to obtain the physical adress of a bank, but it isn't a common situation. |
| ||
Thanks for the informnation. But by giving the pointer to the DLL works here. I haven to give 4 pieces of information in mem bank as pointer in one file. Try it today and the information is working. The strobe was not good in the first place thats why i got onlhy a dot on the display. But now i have all the characters i want. Thanks for the help guy's |