Primitive Failed With A C++ DLL

VA Smalltalk is a "100% VisualAge compatible" IDE that includes the original VisualAge technology and the popular VA Assist and WidgetKit add-ons.

Moderators: Eric Clayberg, wembley, tc, Diane Engles, solveig

Primitive Failed With A C++ DLL

Postby bresendez » Tue Jan 13, 2009 7:35 am

I am trying to talk to a simple dll from Smalltalk. I use the following for the call

|aPlat rc|
aPlat := PlatformFunction
callingConvention: 'C'
function: 'getURL'
library: 'c:\benr\TaxURL2.dll'
parameterTypes: #()
returnType: #char.

rc := aPlat call.
^rc

The function in C++ is defined as
char* getURL(void)

when executing the smalltalk I get
Primitive failed in: PlatformFunction>> #call due to OS error14001

Obtaing the error by executing PlatformFunction getErrorStringArray I get
Error opening library C:\BENR\TAXURL2: This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem.

Is there some sort loading I must perform or is am I forgetting to set a vairaible properly?
bresendez
 
Posts: 6
Joined: Tue Jan 13, 2009 7:00 am

Re: Primitive Failed With A C++ DLL

Postby marten » Tue Jan 13, 2009 9:05 am

Some points:

I think, that the definition should be:

|aPlat rc|
aPlat := PlatformFunction
callingConvention: 'C'
function: 'getURL'
library: 'c:\benr\TaxURL2.dll'
parameterTypes: #()
returnType: #pointer.

I would also assume, that the dll you mentioned above does not link to any other libraries ? Otherwise it would be a good idea to copy
all needed dll's to your Smalltalk directory. I would take a closer look on this point - perhaps some runtime libraries (from your compiler) are missing ? VS2005 ?

I also assume, that the method you mentioned is really a c function and not a C++ function.
Marten Feldtmann, Principal Smalltalk User, Private
SkypeMe callto://marten.feldtmann
marten
[|]
 
Posts: 641
Joined: Sat Oct 14, 2006 7:10 am
Location: Hamburg - Germany

Re: Primitive Failed With A C++ DLL

Postby bresendez » Tue Jan 13, 2009 10:28 am

I changed the returnType to pointer. I get the same error message. The function is a C++. We have other dll that were written in C and I am able to communicate with them using the PlatformFunction. But in this case I am given a C++ dll. Is there something different about c++ versus c?
bresendez
 
Posts: 6
Joined: Tue Jan 13, 2009 7:00 am

Re: Primitive Failed With A C++ DLL

Postby marten » Tue Jan 13, 2009 11:04 am

bresendez wrote:I changed the returnType to pointer. I get the same error message. The function is a C++. We have other dll that were written in C and I am able to communicate with them using the PlatformFunction. But in this case I am given a C++ dll. Is there something different about c++ versus c?


You can not do a call to a C++ library from any other system system - except from the original C++ compiler runtime system (even not from other C++ compilers - though the compiler vendors are working on a standard). To communicate with such a C++ call you have to build a plain C function (with that compiler) and call the C++ based function from that C function and with your Smalltalk code you call that new C based function, which simply returns the value of the C++ call.

Marten
Marten Feldtmann, Principal Smalltalk User, Private
SkypeMe callto://marten.feldtmann
marten
[|]
 
Posts: 641
Joined: Sat Oct 14, 2006 7:10 am
Location: Hamburg - Germany

Re: Primitive Failed With A C++ DLL

Postby bresendez » Thu Jan 22, 2009 9:46 am

I am now calling the C module. I am able to make basic calls for example.
|aPlat rc|
aPlat := PlatformFunction
callingConvention: 'C'
function: 'getURLString1'
library: 'c:\ben\staticDLL.dll'
parameterTypes: #()
returnType: #pointer.
rc := aPlat call.
^rc

The rc is either a 0 or 1.

Now I am trying to call another function but this time the function signature is different
char* getURLString2(int requestedURL)

aPlat := PlatformFunction
callingConvention: 'C'
function: 'getURLString2'
library: 'c:\ben\staticDLL.dll'
parameterTypes: #(int8)
returnType: #pointer.
rc := aPlat callWith: 1.
^rc

Executing this I get a smallint. I expected to get an array of chars. Any ideas as to why I get a smallint?
bresendez
 
Posts: 6
Joined: Tue Jan 13, 2009 7:00 am

Re: Primitive Failed With A C++ DLL

Postby marten » Thu Jan 22, 2009 10:02 am

bresendez wrote:I am now calling the C module. I am able to make basic calls for example.
|aPlat rc|
aPlat := PlatformFunction
callingConvention: 'C'
function: 'getURLString1'
library: 'c:\ben\staticDLL.dll'
parameterTypes: #()
returnType: #pointer.
rc := aPlat call.
^rc

The rc is either a 0 or 1.


Which seems to be wrong, right ?? It returns a pointer (==address) to a character - but that can not
be 0 or 1.

Marten
Marten Feldtmann, Principal Smalltalk User, Private
SkypeMe callto://marten.feldtmann
marten
[|]
 
Posts: 641
Joined: Sat Oct 14, 2006 7:10 am
Location: Hamburg - Germany

Re: Primitive Failed With A C++ DLL

Postby bresendez » Thu Jan 22, 2009 10:40 am

Actually I am getting 0, not the address on the first function call. On the second function call i get a small int which I assume is the address. If it is the address value how would you read the actual value?
bresendez
 
Posts: 6
Joined: Tue Jan 13, 2009 7:00 am

Re: Primitive Failed With A C++ DLL

Postby nmongeau » Thu Jan 22, 2009 10:49 am

Try inspecting this:

OSStringZ address: yourIntValue
nmongeau
[|]
 
Posts: 29
Joined: Fri Jan 12, 2007 9:37 am

Re: Primitive Failed With A C++ DLL

Postby marten » Thu Jan 22, 2009 11:18 am

bresendez wrote:Actually I am getting 0, not the address on the first function call. On the second function call i get a small int which I assume is the address. If it is the address value how would you read the actual value?


0 is a null pointer - which might be ok. A small integer number as an address - seems to be suspect.

Just an idea - within your example function (getURLString1) just return a fixed string (a constant) - and then play around with that function until you get the expected string within your Smalltalk system. Then you are confident, that your Smalltalk - C interaction is working. Than exchange the returned value to the one from your "main" system. If that is not working, you have not a Smalltalk problem, but more or less a C <-> C++ problem.

Marten
Marten Feldtmann, Principal Smalltalk User, Private
SkypeMe callto://marten.feldtmann
marten
[|]
 
Posts: 641
Joined: Sat Oct 14, 2006 7:10 am
Location: Hamburg - Germany

Re: Primitive Failed With A C++ DLL

Postby bresendez » Thu Jan 22, 2009 12:21 pm

Thank you for your help. That did the trick!
bresendez
 
Posts: 6
Joined: Tue Jan 13, 2009 7:00 am


Return to VA Smalltalk 7.0, 7.5 & 8.0

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest