views:

46

answers:

1

hi guys, i'm a newbie to ASP.net interop features, so what i have right here is some unmanaged dll that i need to call from my asp.net mvc app.

the dll name is CTSerialNumChecksum.dll. i can easily call the dll from asp using just those two lines below and from my trusty response. write everything is working fine.

set CheckSumObj = Server.CreateObject("CTSerialNumChecksum.CRC32API")
validSno        = CheckSumObj.ValidateSerialNumber(no)

i know it's unmanaged because when i try to add reference to the dll it doesn't work. i try to follow some tutorials on interop and marshalling but thus far i wasn't able to get the code to work.

i'm trying to wrap the object into another static class and just let the rest of the app to call the code. so not sure why is it so hard to get it working in asp.net or that i'm just an idiot arggghhh..

using System;
using System.Runtime.InteropServices;

namespace OnlineRegisteration.Models
{
    public static class SerialNumberChecksum
    {
        [DllImport("CTSerialNumChecksum")]
        public static extern int ValidateSerialNumber(string serialNo);

    }
}

Questions:

  1. How do i write the class? most example i found didn't involve the class, the .CRC32API part, and those that do seems freaky hard
  2. And what tool can i use to identify what type of dll a particular file is, i.e. unmanaged c++, etc?
  3. Also i intend to make use jquery to do ajax call later so i can use this to validate my form pre-submission. Is there a better way to handle this?

Dumpbin call returned me this, not sure why i can't see the validate function name inside:

File Type: DLL

  Section contains the following exports for CTSerialNumChecksum.DLL

    00000000 characteristics
    3D75BB53 time date stamp Wed Sep 04 15:50:43 2002
        0.00 version
           1 ordinal base
           4 number of functions
           4 number of names

    ordinal hint RVA      name

          1    0 000015CB DllCanUnloadNow
          2    1 000015D7 DllGetClassObject
          3    2 000015F1 DllRegisterServer
          4    3 00001601 DllUnregisterServer

  Summary

        5000 .data
        2000 .rdata
        2000 .reloc
        2000 .rsrc
        8000 .text

Updates:

Could this be due to name mangling? as it's a c++ dll, at least what i suspect it to be anyway...

+2  A: 

It is a COM object. I can tell because Server.CreateObject() in ASP is the way to instantiate a COM object. The DllRegisterServer and so on in the DLL, are also telltale signs.

You want to use the COM object from .NET. You can do that by generating an interop assembly, at compile time, by running the tlbimp.exe tool. Basically, this does, automatically, what you were trying to do manually. Then compile your code with the resulting assembly.

As for the jQuery part - I think you should leave that to a completely separate question.


ps: I don't know what that CRC32API thing does, but there are CRC32 implementations available in C#. You might consider re-implementing whatever function is in that COM object, in all-managed code. It would eliminate the need for tlbimp.exe at compile time, and the registration of the COM object at runtime.

Cheeso
yup it's a com alright, thanks :)
melaos