problem in using delphi DLL in c#

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



hi,

I am using c# to call a DELPHI.DLL, but I don't think I do it
properly. Please help me check the codes:

I use the example way in MSDN to covert the unmanaged DLL to fit
for .net framework.

I try to use the "injectLibrary(..)" in DELPHI.DLL to inject a A.DLL
to a notepad.exe process.(the function is correct in vc60). if A.DLL
is loaded in any process,a messagebox will pop up.

firstly,I change the prototype for the two API from unmanaged DLL. one
is madchook.dll,the other is kernel32.dll.
*****************************prototype for unmanaged
api****************************************
[DllImport("DELPHI.DLL", EntryPoint =
"InjectLibraryW",CallingConvention=CallingConvention.StdCall,SetLastError
=true )]
public extern static Boolean InjectLibrary
(
IntPtr dwProcessHandleOrSpecialFlags,
[MarshalAs(UnmanagedType.LPStr)]String pLibFileName,
IntPtr dwTimeOut
);

[DllImport ("kernel32.dll",EntryPoint
="LoadLibraryW",CallingConvention=CallingConvention.StdCall,SetLastError
=true)]
public extern static ModuleHandle LoadLibrary
(
[MarshalAs(UnmanagedType.LPTStr)]string lpFileName
);

******************************************************************************************************************

then,i call the two API .
**********************************call the two api in
c#******************************************************
bool result = false;
int err = 0;
Process[] p =
System.Diagnostics.Process.GetProcessesByName("notepad");
result = InjectLibrary(p[0].Handle, "A.dll",
(System.IntPtr)7000);
err=Marshal.GetLastWin32Error();
ModuleHandle mh = LoadLibrary("A.dll");
******************************************************************************************************************

the result is always false. the error code is 2;(even if the file path
is comlete and the notepad process is founded,the p[0].handle has
correct value).and i counldn't find code 2 in win32 error codes.
but the "loadlibrary(..)"call is perfectly right,I can see the pop up
messagebox.

The detail about the DELPHI.DLL is complicated.It's written in
delphi,but i has c++ prototype in .h file where its calling convention
is stdcall. and the lib files have two versions,one is called
"dynamics version" which means late binding , the other is "static
version". I am really confused by all these files, how should I use
them?


so does anybody have a clue about this?
or just tell me how to use madcodehook in .net framework? should I
wrap the dll in vc++.net, then add it into C# project?

thank you very much.
.



Relevant Pages

  • how to use delphi dll in C#
    ... firstly,I change the prototype for the two API from unmanaged DLL. ... the error code is 2;(even if the file path ... is comlete and the notepad process is founded,the p.handle has ... correct value).and i counldn't find code 2 in win32 error codes. ...
    (microsoft.public.dotnet.languages.csharp)
  • [PATCH 01/16] trivial: fix assorted "success" typos
    ... Subject: trivial: fix assorted "success" typos ... error code otherwise. ... + * called once we have a lock from a successful search ... Return codes ...
    (Linux-Kernel)
  • Re: Help configuring sendmail to send only using authorization to smart host
    ... stat=Data format error'' error code is described (along ... A permanent failure is one which is not likely to be resolved by ... X.6.X Message Content or Media Status ... The message content or media status codes report failures ...
    (freebsd-questions)
  • Re: [PATCH] mmc_spi: do propper retry managment in the block layer - 3rd try
    ... So somewhere I will need to have an error code filter based on the issued ... The command is typically implicit given in the function, ... Only one handling for different drivers, ... There is no clear definition of which error codes should be reported to the ...
    (Linux-Kernel)
  • RE: How to find crashing problem (driver)
    ... general info on most of those codes. ... >> I can go into msconfig and do selective startup and diagnostic startup and ... > Check the error code when your "bluescreen" comes up, ...
    (microsoft.public.windowsxp.general)