473,804 Members | 3,649 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retrieving BSTR * from a DLL

I need to interface with a windows DLL that has the following
signature

extern "C" void Foo( BSTR in, BSTR *out )

Code so far
>>from ctypes import *
import comtypes
LPBSTR = POINTER(comtype s.BSTR)

hdl = windll.MyDll.Fo o
hdl.rettype = None
hdl.argtype s = [comtypes.BSTR, LPBSTR]

inStr = comtypes.BSTR(u 'Some Silly String')
out = comtypes.BSTR

hdl(inStr,byr ef(out))
Traceback (most recent call last):
File "<pyshell#1 4>", line 1, in <module>
hdl(inStr,byref (out))
TypeError: byref() argument must be a ctypes instance, not
'_ctypes.Simple Type'

Also tried the following
>>out = comtypes.BSTR(u '')
p = pointer(out)
hdl(inStr,p )
Traceback (most recent call last):
File "<pyshell#1 9>", line 1, in <module>
hdl(inStr,p)
ValueError: Procedure probably called with too many arguments (8 bytes
in excess)

Any feedback would be appreciated.
Jul 9 '08 #1
2 5858
mzdude wrote:
I need to interface with a windows DLL that has the following
signature

extern "C" void Foo( BSTR in, BSTR *out )

Code so far
>>>from ctypes import *
import comtypes
LPBSTR = POINTER(comtype s.BSTR)

hdl = windll.MyDll.Fo o
hdl.rettyp e = None
hdl.argtyp es = [comtypes.BSTR, LPBSTR]

inStr = comtypes.BSTR(u 'Some Silly String')
out = comtypes.BSTR
out = comtypes.BSTR()
>>>hdl(inStr,by ref(out))

Traceback (most recent call last):
File "<pyshell#1 4>", line 1, in <module>
hdl(inStr,byref (out))
TypeError: byref() argument must be a ctypes instance, not
'_ctypes.Simple Type'
comtypes.BSTR is a type; the type error makes clear you need
an instance, as above.
Also tried the following
>>>out = comtypes.BSTR(u '')
p = pointer(out)
hdl(inStr, p)

Traceback (most recent call last):
File "<pyshell#1 9>", line 1, in <module>
hdl(inStr,p)
ValueError: Procedure probably called with too many arguments (8 bytes
in excess)
This likely indicates that the DLL is using the C calling convention
and not the stdcall calling convention. Use CDLL rather than WinDLL
to load the DLL.

You might like to join the ctypes-users mailing list at sourceforge.

--
-------------------------------------------------------------------------
Andrew I MacIntyre "These thoughts are mine alone..."
E-mail: an*****@bullsey e.apana.org.au (pref) | Snail: PO Box 370
an*****@pcug.or g.au (alt) | Belconnen ACT 2616
Web: http://www.andymac.org/ | Australia
Jul 10 '08 #2
On Jul 10, 6:15*am, Andrew MacIntyre <andy...@bullse ye.apana.org.au >
wrote:
<snip>
This likely indicates that the DLL is using the C calling convention
and not the stdcall calling convention. *Use CDLL rather than WinDLL
to load the DLL.
using cdll got me over the calling hurdle. However, I'm not seeing the
returned BSTR.
You might like to join the ctypes-users mailing list at sourceforge.
I did, thanks.
Jul 10 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5750
by: Chris | last post by:
I am not sure if this is the right newsgroup. But does anyone know what is the difference between a BSTR and a LPOLESTR? The only thing I could find out is that the advantage of taking BSTR instead of LPOLESTR is that determining the length of a BSTR is much faster.
2
5074
by: banski | last post by:
Hi, Im trying to find out how to convert a SYSTEMTIME to BSTR. Cant find out how to do that. Hopefully some of you could help me out. Best regards Thomas
7
7128
by: Gilad Walden | last post by:
I use C# in .NET framework. I have an ActiveX implemented in C++ that has a COM interface method that gets as it’s out parameter a BSTR* . The interop translates this BSTR* into C# string. From my managed code, I am calling that function with ‘out’ parameter of ‘string’ type. For normal size strings it works fine, but when the string is very big (> 50,000 bytes), I get a null exception from the COM interop. What is the reason?...
8
5198
by: Michael Tissington | last post by:
I have a C++ function in a DLL of the form BSTR WINAPI DoSomeWork(LPCSTR szConnection, LPCSTR szGUID) I use SysAllocStringByteLen to return a BSTR. For the most part this works accept when the calling applicaiton tries to free the BSTR and I get a RtlFreeHeep error. I'm guessing because the bstr has been allocated in one dll and it being released in another.
0
1273
by: Edwin Knoppert | last post by:
I'm currently using a wrapper which converts an ANSI BSTR from a dll. (Yes, singlebyte but BSTR ! ) This works fine and i'm aware BSTR's returned must be destroyed by the caller, which i do. I noticed that ASP.NET's 'AS STRING' doesn't return the BSTR having char(0)'s. So i must assume ASP.NET does not destroy the BSTR + i need the real data.
5
2665
by: bluter | last post by:
We have server components which were created by a third party and compiled in VC++5 (sp3). They run fine on NT4 and 2000, however during testing of our migration to Server 2003, these components have been failing when performing Data Access functions. In particular we have been having problems with BSTR and _bstr_t. _bstr_t(BSTR*, 1) is the original code that the problem started with. Other findings are - 1) Converting a BSTR* to a...
37
5480
by: Egbert Nierop \(MVP for IIS\) | last post by:
In win32 mode, a BSTR was UINT length prefixed and terminated exactly by a zero char. So if you allocated "Hello World" that would allocate 28 bytes. In x64 and (IA64 as well) it would become 32 bytes, because of the fact that a pointer, is 8 bytes instead of 4 bytes. The length prefix -still- is a UINT however and not a UINT_PTR.
2
1543
by: Lucy Ludmiller | last post by:
How can I write a function like this: BSTR Greeting(BSTR name) { //return "Good Morning : " + name ; } In short I'm looking for a quick tutorial on using BSTR - Google is not bringing up anything consise enough (I'm not particularly interested in the history of BSTR and the differences between string types etc ...
0
1869
by: Jason Smiley | last post by:
So I have a function that is called from a COM object that has a BSTR as an out paramater. A code snippet looks like this: MyComLib.MyComInterface tester = new MyComLib.MyComInterface(); // Size represents the size of the BSTR and is an integer, BSTR is a BSTR on // the C++ side of the Interface, but is a normal String on my side in C#. tester.WaitForData(ref Size, out BSTR); When I try to access the data inside of BSTR, only the...
0
9704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9569
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10558
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10318
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10302
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6844
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5503
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.