call C function from DLL using smalltalk

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

call C function from DLL using smalltalk

lhhuong
Hi all, I created a simple dll to try the Dll&C connect
#include <iostream>
#define DLLExport _declspec(dllexport)
DLLExport int sum(int arg1, int arg2){
        return arg1+ arg2;
}


In smalltalk, I created a class named: DLLTest and a function:
sum: arg1 with: arg2
        <C: int sum(int arg1, int arg2)>
        ^self externalAccessFailedWith: _errorCode


When I received the error when I run: DLLTest new sum: 1 with: 2 command.

But when I called abs function in msvcrt40.dll. It works.

What should I do to fix it? Thank all.
Reply | Threaded
Open this post in threaded view
|

Re: call C function from DLL using smalltalk

skrish

"External Object not found"  error string seems to indicate you have not placed the DLL in that path that it is loaded while you start/ restart Visualworks.

* procexp.exe  will be able to show you in the handles, the dll's the vw process loads in its lower pane.
   * Check first if the DLL is loaded with your call
   * If dll is loaded then the probability exists of the method not being correctly exported
      ( but your code is simple and the only the other reason is putting in Extern C )
#define EXTERN_DLL_EXPORT extern "C" __declspec(dllexport)   ( create the dll as a C Project not C++ )

http://stackoverflow.com/questions/538134/exporting-functions-from-a-dll-with-dllexport

   Once you go past this barrier, you can also have Visual Studio be able to debug step through the C DLL function code by attaching to the VW process.



On Sun, Mar 1, 2015 at 2:00 PM, lhhuong <[hidden email]> wrote:
Hi all, I created a simple dll to try the Dll&C connect
/#include <iostream>
#define DLLExport _declspec(dllexport)
DLLExport int sum(int arg1, int arg2){
        return arg1+ arg2;
}/

In smalltalk, I created a class named: DLLTest and a function:
/sum: arg1 with: arg2
        <C: int sum(int arg1, int arg2)>
        ^self externalAccessFailedWith: _errorCode/

When I received the error when I run: DLLTest new sum: 1 with: 2 command.
<http://forum.world.st/file/n4808619/error.jpg>
But when I called abs function in msvcrt40.dll. It works.

What should I do to fix it? Thank all.



--
View this message in context: http://forum.world.st/call-C-function-from-DLL-using-smalltalk-tp4808619.html
Sent from the VisualWorks mailing list archive at Nabble.com.
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: call C function from DLL using smalltalk

Tom Robinson-4
Can you provide a listing of your DLLTest class definition?

On 3/1/15 4:07 AM, Sudhakar Krishnamachari wrote:

"External Object not found"  error string seems to indicate you have not placed the DLL in that path that it is loaded while you start/ restart Visualworks.

* procexp.exe  will be able to show you in the handles, the dll's the vw process loads in its lower pane.
   * Check first if the DLL is loaded with your call
   * If dll is loaded then the probability exists of the method not being correctly exported
      ( but your code is simple and the only the other reason is putting in Extern C )
#define EXTERN_DLL_EXPORT extern "C" __declspec(dllexport)   ( create the dll as a C Project not C++ )

http://stackoverflow.com/questions/538134/exporting-functions-from-a-dll-with-dllexport

   Once you go past this barrier, you can also have Visual Studio be able to debug step through the C DLL function code by attaching to the VW process.



On Sun, Mar 1, 2015 at 2:00 PM, lhhuong <[hidden email]> wrote:
Hi all, I created a simple dll to try the Dll&C connect
/#include <iostream>
#define DLLExport _declspec(dllexport)
DLLExport int sum(int arg1, int arg2){
        return arg1+ arg2;
}/

In smalltalk, I created a class named: DLLTest and a function:
/sum: arg1 with: arg2
        <C: int sum(int arg1, int arg2)>
        ^self externalAccessFailedWith: _errorCode/

When I received the error when I run: DLLTest new sum: 1 with: 2 command.
<http://forum.world.st/file/n4808619/error.jpg>
But when I called abs function in msvcrt40.dll. It works.

What should I do to fix it? Thank all.



--
View this message in context: http://forum.world.st/call-C-function-from-DLL-using-smalltalk-tp4808619.html
Sent from the VisualWorks mailing list archive at Nabble.com.
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc



_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: call C function from DLL using smalltalk

lhhuong
In reply to this post by lhhuong
I had a mistake, I did not set the *.so file in the "library file". Now, it work.

Thank you very much.

Best wishes.