Share data between C# and Delphi with madshi IPC

c++ / delphi package - dll injection and api hooking
madshi
Site Admin
Posts: 10328
Joined: Sun Mar 21, 2004 5:25 pm

Re: Share data between C# and Delphi with madshi IPC

Post by madshi »

Sorry for the late reply. I've tried to download your sample now, but I failed. I'm getting redirected through multiple sites, asked to turn off my ad blocker, asked to allow notification, and still no download link. Could you please use a proper file host? E.g. try mediafire.
ExPx
Posts: 34
Joined: Fri Oct 21, 2016 3:20 pm

Re: Share data between C# and Delphi with madshi IPC

Post by ExPx »

madshi
Site Admin
Posts: 10328
Joined: Sun Mar 21, 2004 5:25 pm

Re: Share data between C# and Delphi with madshi IPC

Post by madshi »

Not sure why, but it seems to work fine here without crashes. Can you double check? Here's my build, compiled with XE8 using madCodeHook v4:

http://madshi.net/IPCCrashTest.rar
ExPx
Posts: 34
Joined: Fri Oct 21, 2016 3:20 pm

Re: Share data between C# and Delphi with madshi IPC

Post by ExPx »

I tested and it seems working very well. I mixed yours and my examples. Your 32bit receiver part works good.
madshi
Site Admin
Posts: 10328
Joined: Sun Mar 21, 2004 5:25 pm

Re: Share data between C# and Delphi with madshi IPC

Post by madshi »

I'm not sure if it's the difference between v3 and v4, or maybe XE2 vs XE8? I think it's more likely v3 vs v4.
madshi
Site Admin
Posts: 10328
Joined: Sun Mar 21, 2004 5:25 pm

Re: Share data between C# and Delphi with madshi IPC

Post by madshi »

I've uploaded XE2 v4 and XE8 v3 builds here, for you to test:

http://madshi.net/IPCCrashTest2.zip
ExPx
Posts: 34
Joined: Fri Oct 21, 2016 3:20 pm

Re: Share data between C# and Delphi with madshi IPC

Post by ExPx »

Company firewall doesnt allow download (virus alert). I will try at home.
ExPx
Posts: 34
Joined: Fri Oct 21, 2016 3:20 pm

Re: Share data between C# and Delphi with madshi IPC

Post by ExPx »

I tried both mine and your demos at home. IPCCrashTestApp XE2 v4 working well. IPCCrashTestApp XE8 v3 crashes like mine.
madshi
Site Admin
Posts: 10328
Joined: Sun Mar 21, 2004 5:25 pm

Re: Share data between C# and Delphi with madshi IPC

Post by madshi »

Oh well, looks like a bug in v3 then, probably... :(
ExPx
Posts: 34
Joined: Fri Oct 21, 2016 3:20 pm

Re: Share data between C# and Delphi with madshi IPC

Post by ExPx »

I upgraded to v4 and problem solved.

One more question. How can I use AddAccessForEveryone. Can you provide sample ? I am planning to run this code in delphi service AfterInstall event.
jonny_valentine
Posts: 109
Joined: Thu Dec 30, 2004 9:59 pm
Location: UK

Re: Share data between C# and Delphi with madshi IPC

Post by jonny_valentine »

ExPx wrote:Hi madshi,

Any progress for this issue ?
Just to let you know that it is completely possible to use the IPC between (any language) c++ DLL and c# application as i use it already. Its not easy to push callbacks of this nature into c#, you need to be 3l1t3 ;)

There is no bug with the MCH/SendIPC system...
iconic
Site Admin
Posts: 974
Joined: Wed Jun 08, 2005 5:08 am

Re: Share data between C# and Delphi with madshi IPC

Post by iconic »

Hmmm after taking a look at the posted code from ExPx for the IPC callback it's using the updated prototype which includes the extra Context pointer parameter. Well, if a user was using MCH v3.x (which he was) with the updated IPC callback prototype from MCH v4.x, this could cause issues. Case example below:

Code: Select all

MCHv3.CreateIpcQueue(IPC_NAME, @Callback);

Code: Select all

MCHv4.Callback(lpName: PChar;
                         lpMessageBuf: PWChar;
                         dwMessageLen: DWORD;
                         lpAnswerBuf: Pointer;
                         dwAnswerLen: DWORD;
                         lpContext: Pointer <--- unexpected);
That's assuming lpContext param addition was specifically introduced in v4 and wasn't used in v3. I'm a 4.x user so I'd have to check the older prototype. The help docs only show the newest/latest (v4.x) ...

--Iconic
madshi
Site Admin
Posts: 10328
Joined: Sun Mar 21, 2004 5:25 pm

Re: Share data between C# and Delphi with madshi IPC

Post by madshi »

Good catch, iconic! That might explain the problem nicely.

@ExPx, you should not have to call AddAccessForEveryone yourself, CreateIpcQueue already does that for you internally. But anyway, if you want to know how to call it, you can check "InjectService.cpp" in this demo:

http://madshi.net/HookProcessTermination.zip
ExPx
Posts: 34
Joined: Fri Oct 21, 2016 3:20 pm

Re: Share data between C# and Delphi with madshi IPC

Post by ExPx »

Thanks Madshi It worked. I had to change service installation procedure in SvcMgr pas becuse AfterInstall event doesn't expose SC_HANDLE result of CreateService.
Post Reply