Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Registering and using a .NET DLL from within Delphi (XE2)

Status
Not open for further replies.

Nefarious1

Programmer
Feb 24, 2014
13
0
0
GB
Hi -

Some time ago, I developed a small app to communicate with some hardware using a DLL (supplied by the manufacturers of the hardware.) Recently however, they decided to re-write the API and wrap it in a .NET DLL. Now its been hell to try use this thing.

Here is an extract from an email relating to this issue..

Supplier said:
"We have chosen not to continue forward with the ActiveX OCX technology ..Rather a .Net-compliant DLL that is fully compatible with Win XP/7 (32/64-bit) and Win8.x 64-bit platforms. This solution does not require system registration and in this aspect alone, we feel makes this solution superior to the ActiveX environment..."

Although they say that the DLL does not need to be registered - is this correct ? I was led to believe that to use a .NET DLL from withing my software it would first have to be registered (using Regasm ?).

I have googled this issue but not found anything very helpful. They supplied 2 files a DLL and a Type file (.tlb) I tried importing the .Net assembly into delphi (not sure it I did it right - or if indeed I needed to) and it produced a .pas file that I place in the uses section and it seems to work (after a fashion.)


Here is a link to the delephi-created wrapper for the .NET assembly..

Link

Now I have it working on 1 computer.. using the following code..

In the "OnCreate" event on the main form I have..

Code:
Var
Drawer  : USBQFUMC_;
begin..
Drawer := CoUSBQFUMCCLS.Create as USBQFUMC_;
end;

Now as I say, I have got this running on 1 computer - but I am having problems installing it on other computers (all are using Windows 8.1.) On the other computer I tried to install it on - I get an error relating to the fact the Class or DLL is not registered. I have tried many ways of using regasm to try remedy this - but none seem to work.

Can someone please tell me if I am going about this all wrong - or is there an easier (not reliable) way to get this working ? IS there any way to access the .NET DLL from within delphi WITHOUT registering the .DLL (as the supplier implied ?)

Any help would be much appreciated..

Many thanks..

Dave.







 
Seems odd that you have it working on one computer, since the supplier states that they do not longer provide and ActiveX/OCX.
I suspected you still have the old DLL registered on that machine.
The only way you can interface with a native .NET DLL is from .NET.
What I usually do is make an intermediary COM visible .NET DLL that consumes the real .NET DLL and expose the wanted functionality through the COM interface.

/Daddy

-----------------------------------------------------
Helping people is my job...
 
Thanks for the tip regarding Hydra - but at $400 - its not a realistic solution for me. The problem is that I have had very little to do with COM or .NET so both technologies are new to me, so Im afraid the solution Daddy's solution is not gong to help me much.

I think that the reason 1 computer seemed to work ok and the others didn't is probably to do with OS-specific stuff (privileges etc..)

I know its not because the old DLL is registered as its the new code that worked - not the old code
old code said:
"..dllHandle := LoadLibrary(PChar(DLLPath));"


If anyone has some reasonably easy-to-follow code I will be all ears :). Also will it be necessary to use regasm to register the DLL before use ? Or are they correct when they say it needs no registration ?

Thanks.


 
Ok, I slow down and think with me please.

If I look on this page,
I can see that there are 2 versions :

- APG USBQFUMC v1.00 : this is a COM visible .NET DLL which needs to be registered via the .NET RegAsm tool as instructed by the documentation.
- APG USBQFDNETSUSN v110 : this is a pure .NET DLL which can not be registered with RegAsm as it does not expose a COM interface (and therefore cannot be consumed in Delphi).

So what version are you attempting to use?

/Daddy



-----------------------------------------------------
Helping people is my job...
 
Hi Daddy -

I have been using the USBQFUMC.DLL version. As I say, I did ,manage to get it working on 1 comp after a fashion - just cant seem to get it working on 2 other similar configured computers (all use Windows 8.1.)

I think the problem may be with registering it on the OS. I am not 100% sure of the correct command line arguments, but it does seem to register ok (it generates no error messages anyway.) I first tried using Inno to register it during a test installation. When it came up with errors using the App I wrote - I tried registering it manually from the command line. Here is one such attempt..

Code:
 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm.exe C:\ctest\USBQFUMC.dll

This comes back that all went well, but then I get a "ClassID " OLE error when trying to use. I have tried using the 32-bit version of Regasm (In case this was an issue) I have even tried running the different versions of Regasm (based on the various installations of .NET installed - 2 and 4.) Nothing seems to make any difference.

The error message thrown when trying to use the App does not help either. Did Google the code and I think it says "list out of bounds error" or some such. Sounds like a best-guess error message to me. The OLE error is : 80131508.

Here is a screen shot of it..
44iz40snp
OLE_Error.jpg




Anyway, thanks for continued help m8 - its much appreciated :).

Cheers..
 
I don't know if it helps but the docs state clearly you must use the /codebase parameter.
What that parameter essentially does is write the path where the DLL resides into the registry.
If you omit the parameter, the DLL will be copied to the GAC and registered from there.

Can you tell what line is throwing the error you are seeing?

/Daddy

-----------------------------------------------------
Helping people is my job...
 
Hi -

I think I have used nearly every variation of the Regasm commandline I think. However, I may have used the "/codebase" parameter using Inno script (not sure if I have used it manually - so maybe I can give that a go.

The line that generates the error I posted is where I first attempt to create an instance of the object in my app. Here is the line that generates the error..

Code:
var
Drawer  : USBQFUMC_;
begin
Drawer := CoUSBQFUMCCLS.Create as USBQFUMC_;
end;

Cheers..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top