C#: A dynamic link library (DLL) initialization routine failed

0

I am trying to replicate some functionality of other app, which uses CyStat.dll. Here is the app itself

https://mega.nz/#!sIRggKST!UEeAWgcT9ONbyc0WgFagI-0G36zxvEK1dMwzw3NYd60

It's basically a status monitoring tool for a specific printer

My problem is this: I get this error every time I try to use the dll:

'Unable to load DLL 'CyStat.dll': A dynamic link library (DLL) initialization routine failed. (Exception from HRESULT: 0x8007045A)'

I know that usually that is because some dependencies are missing. Here are the dependencies that it uses:

enter image description here

They are definitely present on my machine, and by the way, original app that I am trying to replicate, works fine

Here is the code I use to call the methods from the dll:

    [DllImport("CyStat.dll", CharSet = CharSet.Ansi, SetLastError = true)]
    public static extern int CvInitialize([MarshalAs(UnmanagedType.LPWStr)] string pszPortName);

    var res = CvInitialize("DS-RX1");

I also tried decompiling that app and copy-pasting code from there, but it fails with the same error

Thanks in advance for any help

c#
dll
dllimport
asked on Stack Overflow Jun 5, 2019 by SaintMSent • edited Jun 5, 2019 by Franck

1 Answer

1

So, I had that error in question accompanied by the System.DllNotFoundException, which I did not notice right away My dll was dependent on kernel32.dll and winspool.drv. When I noticed that exception, I realized that I tried to load 32 bit dll on my 64 bit system. So I just tried 64 bit version and it worked perfectly

answered on Stack Overflow Jun 8, 2019 by SaintMSent

User contributions licensed under CC BY-SA 3.0