• Welcome to Theos PowerBasic Museum 2017.

BSTRs In Low Level COM

Started by Frederick J. Harris, August 24, 2010, 12:57:05 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Frederick J. Harris

I'm doing the write-up for that out of process server example I posted some time ago in the hope of posting a better description of how it works, and I wanted to double check on my understanding of how I dealt with the BSTRs which were instance variables in my class CC which were Get/Set by interface functions.  Since the only way I know to persist BSTRs in a PowerBASIC Type is with a member Dword or Dword Ptr variable (PowewrBASIC Types can't store variable length strings), that's what I did.  Am I right in assumming this is the only way to do this?  In C++ the BSTRs are just a member of a struct, but I'm assumming I have to do essentially the same thing in low level COM PB.  Not so?

José Roca

Declare the member as DWORD, allocate the string with SysAllocString and fill that member with the pointer returned by the function. When no longer needed, free the memory with SysFreeString.

Frederick J. Harris

Maybe I'm wrong about this, but I seem to have noticed a tendency you have to use just Dwords instead of Dword Ptrs in your code Jose.  Am I wrong about that, or do you have some reason for preferring to to store pointers in Dwords instead of Dword Ptrs?

José Roca

#3
 
The exact type, if PB had native unicode support, would be <Wide string variable type, e.g. WSTRING) PTR, i.e. a pointer to an OLE wide string. If you are going to use the pointer to read the contents using CopyMemory or PEEK$, it doesn't matter if you declare it as LONG, DWORD or something PTR. If you want to use it to read directly the content of the string, then the closer one is WORD PTR, that will allow you to read one unicode character (two bytes) at a time. You may need to do a loop incrementing the pointer until the character returned is a double null. However, if you use DWORD PTR, it will read four bytes each time. DWORD PTR is a pointer to a DWORD, and it is only useful to read DWORDs (I used it with CALL DWORD in my old COM wrapper functions).

So, I use DWORD when it is a void pointer or when I'm not going to deference it.

Charles Pegge


In a 64 bit system a BSTR becomes QWORD instead of DWORD.

Something to watch out for when devising structures containing BSTRs and other pointers and handles.

Charles