Calling C++ DLL call from Delphi

Hi All

I have C++ DLL setup that exports the following function:

    bool ApplyRule(HANDLE DriverDevice, std::string *Path, PROTECTION_TYPE Type, PROTECTION_ACTION Action, bool Architecture64, bool AddRule)

I am not sure how to convert it properly to delphi, inparticular the std::string parameter.

    ApplyRule : function (DriverDevice : THandle; Path : ????; Kind : PROTECTION_TYPE;  Action : PROTECTION_ACTION; Architecture64 : Boolean; AddRule : Boolean) : boolean; stdcall;

Thanks for the help.
0
Chris
6/11/2010 11:45:00 AM
embarcadero.delphi.non-tech 5933 articles. 1 followers. Follow

3 Replies
1911 Views

Similar Articles

[PageSpeed] 13
Get it on Google Play
Get it on Apple App Store

Chris Nillissen wrote:

> I am not sure how to convert it properly to delphi, inparticular the
> std::string parameter.

No chances. 

Normally DLLs should export plane "C" interface (not C++) which can be
translated into another language using known rules.

Class std::string can be implemented differently in different
development tools (BCB, VC, etc.) and implementation definitely will be
incompatible.

-- 
Alex
0
Alex
6/11/2010 12:35:42 PM
Hi, if the DLL is compiled by VS you can create simply small C++ DLL using 
studio express and export pure "C" function. Of course the C function should 
be implemented in such a way, that it calls the original C++ function and 
does some converstion, for example std:string -> char *. Other objects or 
classes if needed. Only basic data types should be left.
I have tried it many times and it works well.
Jarek

Użytkownik "Chris Nillissen" napisał w wiadomości 
news:250938@forums.embarcadero.com...
> Hi All
>
> I have C++ DLL setup that exports the following function:
>
>    bool ApplyRule(HANDLE DriverDevice, std::string *Path, PROTECTION_TYPE 
> Type, PROTECTION_ACTION Action, bool Architecture64, bool AddRule)
>
> I am not sure how to convert it properly to delphi, inparticular the 
> std::string parameter.
>
>    ApplyRule : function (DriverDevice : THandle; Path : ????; Kind : 
> PROTECTION_TYPE;  Action : PROTECTION_ACTION; Architecture64 : Boolean; 
> AddRule : Boolean) : boolean; stdcall;
>
> Thanks for the help.
0
Jarek
6/11/2010 2:37:30 PM
Chris Nillissen wrote:

> Hi All
> 
> I have C++ DLL setup that exports the following function:
> 
>     bool ApplyRule(HANDLE DriverDevice, std::string *Path,
> PROTECTION_TYPE Type, PROTECTION_ACTION Action, bool Architecture64,
> bool AddRule)
> 
> I am not sure how to convert it properly to delphi, inparticular the
> std::string parameter.
> 
>     ApplyRule : function (DriverDevice : THandle; Path : ????; Kind :
> PROTECTION_TYPE;  Action : PROTECTION_ACTION; Architecture64 :
> Boolean; AddRule : Boolean) : boolean; stdcall;
> 
> Thanks for the help.

How you handle this depends on the compiler it was compiled with. If
you know, and can get the code for std::string (which is not trivial),
it could be possible. If the compiler was a recent Microsoft compiler,
it might be possible to create a std::string using the C++ runtime that
comes with every version of Windows, but I never tried this.

I don't know who coded the DLL, but using language- and
compiler-specific types like std::string (every C++ has it, but the
implementation, the internals and the binary interfaces differ greatly)
is a complete no-no. Must be rather inexperienced, or simply didn't
care about others using the DLL.

-- 
Rudy Velthuis (TeamB)        http://www.teamb.com

"There are two ways of constructing a software design. One way
 is to make it so simple that there are obviously no deficiencies.
 And the other way is to make it so complicated that there are no
 obvious deficiencies." -- C.A.R. Hoare
0
Rudy
6/11/2010 7:59:37 PM
Reply:

Similar Artilces:

Calling Delphi 6 DLL from Delphi 2010
We have a Delphi 6 dll that has a PChar passed to it. The dll function then does a search and returns a PCHar. This works good using Delphi 6 to call and recieve the dll result. We have upgraded our calling program to Delphi 2010 and most of the time, the value is passed back just fine. However, we do have times when we get an access violation, when calling the dll. The dll does process the request. Below is the code. Has anyone had a similar issue using an older version Delphi Dll with Delphi 2010? I am sure that Unicode has something to do with it, but not sure how to fix th...

Calling a C++ DLL from Delphi
I use C++ as my main language and nedd to test some stuff with delphi. I have to call a C++ DLL from Delphi. The C++ header is this. class _declspec(novtable) OwnerOfMain { public: virtual void __stdcall DoStatus(long type, long value)=0; }; class _declspec(novtable) Main { public: virtual void __stdcall Delete() = 0; virtual const wchar_t * __stdcall GetTitle() = 0; virtual void __stdcall SetTitle(const wchar_t *) = 0; virtual bool __stdcall Startup(OwnerOfMain *mainOwner)=0; void operator delete(void* p) { if (p) { Main* w = static_cast<Main*>(p)...

Calling Delphi DLL from C#
We have a delphi application that loads the dll dynamically and calls a couple of functions in a Delphi DLL using Load Library, GetProcAddress, and FreeLibrary and all works fine. The DLL is going to be called by a C# application developed in VS 2010. I have the C #code below to test sending and receiving data from the dll and it works ok, but when I close the application or try to resend data, I get an access violation. Do I need to make the calls to the dll using the Load Library, GetProcAddress, and FreeLibrary as well. If so how would I code this in C#? Also I am wondering if I n...

Call c# dll from Delphi 7
Hi, I have a call c# Dll VS2010 .Net Framework 4 from Delphi 7 Professional "add(a+b)". C# code: namespace dll_01 { public interface Iadd { Int32 add_dll(Int32 a, Int32 b); } public class Class1:Iadd { public Int32 add_dll() { return 0; } public Int32 add_dll(Int32 a, Int32 b){ ws_linux_dll.CalculatorWSClient proxy = new ws_linux_dll.CalculatorWSClient(); return Convert.ToInt32(proxy.add(a,b)); } } } After command: regasm dl...

Trying to call a .DLL from Delphi XE (used to work with Delphi 6 :-) )
Hi everyone, I have a problem where perhaps some one could help point me in the right direction. In Delphi 6 I used a stand alone package to train a neural netowrk,. The trained neural network was stored as a .DEF file. The standalone software provided a .DLL and Delphi code to call the network and get the prediced values from your sw. (The .DLL was created in 2002 and apparently is 32 bit.) I have'nt used it for years but am now coming back to it.... I now use Delphi XE on Windows 7 (32 bit) The old .exe's I had compiled from that time work fine. However in Delphi XE ...

Delphi dll
I'm developing a dll file in Delphi 7 in order to use it in a Powerbuilder 10.5 application. I get strange results in PB when i try to pass a string through a function or procedure. I've tried pchar, pwidechar, lpstr, lpctstr in D7 and string or REF string in PB, but nothing seems to be working properly. The function in D7 is quite simple, i just take a string for input, encode it and return an encoded string for output. In PB i get a lot of "squares" in my output string. There seems to be a problem reading (from PB) the memory address that is pointed out from D...

call Delphi-DLL
Hey all, I wanted to call a DLL functions written in Delphi (Pascal). To call the DLL functions I built a Nonvisual-Userobject nvu_call_delphidll in PB6.5 . The PB external function declaration is: FUNCTION long pas_getMin (long x, long y) LIBRARY "MyLib.dll" In the Userobject the code looks like: public function long uf_getmin (long al_x, long al_y); long returnval=0 returnval = pas_getmin(al_x, al_y) return returnval The Delphi 3.0 code for my test DLL is: .... function pas_getMin(x,y: integer): integer; begin if x < y then pas_getMin := x else p...

calling a c++ dll from a delphi vcl app crashes the app upon exit [Edit]
I am using RAD Studio 2010 and I downloaded the latest updates. Since I can't see how I can attach a file to the message, I included in this message the source code for each file: To reproduce this problem follow these steps: Create a project group with two projects, one c++ dll project and one a Delphi VCL forms project. Save all the files in the same folder. 1. Use the wizard to create the c++ dll project, select c++ & Use VCL checkboxes. Make sure Project Options->C++ Linker->Dynamic RTL is set to true. I also added memmgr.lib and sharemem.obj to the project but I bel...

Calling procedure in Delphi dll
I have a dll compiled in Delphi2006 as follows procedure FJDelphi2006CompressStream(AInStream, AOutStream: TStream); begin CompressStream(AInStream, AOutStream); end; procedure FJDelphi2006DeCompressStream(AInStream, AOutStream: TStream); begin DeCompressStream(AInStream, AOutStream); end; exports FJDelphi2006CompressStream, FJDelphi2006DeCompressStream; begin end. I am trying to use this in DelphiXE and I am getting AV's. Could anyone please tell me what needs to be done to get this to work. Regards Sandeep On 22.10.2010 9:36, Sande...

call, call(), .call, and captures
From S06: sub bar ($a,$b,$c,:$mice) { say $mice } sub foo (\$args) { say $args.perl; &bar.call($args); } The C<.call> method of C<Code> objects accepts a single C<Capture> object, and calls it without introducing a C<CALLER> frame. And from S12: In addition to C<next METHOD>, the special function C<call> dispatches to the next candidate, possibly with a new argument list: call; # calls with the original arguments call(); # calls with no arguments call(1,2,3); # calls ...

Calling a form in ,net dll from delphi
Hi I have a Delphi application and I want to dynamically load a .net dll that contains a form and embed this form on my (delphi) form. The original call, from C#, is this: Form componentForm = null; componentForm = dllName.Main.Create(false, "somestring", 3640, "somestring","somestring", 5, true, 4); I have done the following, first I want to see that I manage to load the dll, call the function and get "something" in return: var DLLHandle: THandle; type TDLLFunc = function(param1: boolean; param2: string; param3: integer; param4: string; par...

Java app calling a Delphi DLL
Hello I have a Java application that must call functions inside a large D7 dll. For that, I used JNI calls. That part is OK and the delphi dll is receiving the function parameters smoothly. The Delphi dll has a couple Forms in it. And these Forms are unresponsive. Timers don't work. Buttons will not invoke OnClick handlers. Most important, the assync sockets in the forms, which the dll uses to deliver its work, are not functioning either. It seems that the dll is not receiving Windows messages. I tried to simulate the application loop, but failed. The same DLL works fine i...

Calling C DLL from C#
Hello, I would like to create a C DLL for use with C#. I Understand that there are better ways to do things, but this is the way I have to do it. So esscentially I want to know how to package a C Source file, and associated Header files into a DLL which I can then use in C#. Once I have created a DLL I'm assuming I can use it by: using C_Dll; //Where C_Dll is the C dll. protected C_Dll C_Dll_Object; void somemethod(){   C_Dll_Object = new C_Dll();   int intSomeInt = C_Dll_Object.aReturnFunction();} Can anyone please provide me with an example of this, or a goo...

Calling a DLL from a webform and having the DLL call a webservice.
I want to encapsulate my Data Access layer in a DLL, and i want my DLL handle looking in the web.config and getting the data from a web service defined there.  I tried adding a web Reference but it does nto allow me to do it, so I assume I have to init it by hand. Does anyoe have a snippet on how to init a webservice from a dll, ( hardcoded url is fine, I can do the web.config part easily enough).   Thanks,   Cal- probably WCF can help you: http://msdn.microsoft.com/en-ca/library/ms733133.aspx     I fixed this, I use teh WSDL tool to g...

Web resources about - Calling C++ DLL call from Delphi - embarcadero.delphi.non-tech

London Calling - Wikipedia, the free encyclopedia
London Calling is the third studio album by the English punk rock band The Clash . It was released in the United Kingdom on 14 December 1979 ...

List of country calling codes - Wikipedia, the free encyclopedia
This is a list of country calling codes defined by ITU-T recommendations E.123 and E.164 , also called IDD ( International Direct Dialling ) ...

Free VoIP Calling Added To Facebook Messenger For IOS In The U.K.
Voice-over-Internet-protocol calling has made its way across the pond for Facebook Messenger users, as the social network updated its iOS version ...

Facebook Video Calling - Facebook
Bring your conversations to life on Facebook. With face-to-face video calling, now you can watch your friends smile, wink and LOL. To get started, ...

Facebook roundup: video ads, voice calling, logos and more
... than three per day at launch. It is unclear whether the ads will autoplay in the feed or not. More Messenger for Android users get free calling ...

Berlin Calling (@neuraum) on Twitter
Sign in Sign up To bring you Twitter, we and our partners use cookies on our and other websites. Cookies help personalize Twitter content, tailor ...

Calling all foodies: Here comes @TwitterFood
There are many thousands of food-related Tweets people send on Twitter each day – Tweets about meals, ingredients, favorites, recipes and dining ...

YUBISASHI NIPPON CALLING ENGLISH for iPhone, iPod touch, and iPad on the iTunes App Store
Get YUBISASHI NIPPON CALLING ENGLISH on the App Store. See screenshots and ratings, and read customer reviews.

Calling woman II - Flickr - Photo Sharing!
Explore Marcel Oosterwijk's photos on Flickr. Marcel Oosterwijk has uploaded 2195 photos to Flickr.

They're back. All-Australian Koels calling in ACT suburbia
Too many Gang-gang cockatoos, our dear territory's faunal emblem,&nbsp;are not enough.

Resources last updated: 11/22/2015 5:57:32 AM