0
votes

I have written a COM control in c# .Net 4.5, this COM control uses a 3rd party dll to communicate with a USB device.

On Windows 7 32bit everything works 100% from both VBScript and the VB6 app. On Windows 7 64bit the VBScript fails when calling the 3rd party dll function that uses the USB device.

The exception is: "System.AccessViolationException" with message: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

What I don't understand is that the same COM control (and the same USB driver) works when instantiated from the VB6 app, but not from the VBScript.

I have looked at the loaded assemblies and registry access using Process Monitor when running the VB6 app and the VBScript but I cannot see anything out of the ordinary.

Any suggestions of what I can troubleshoot or test next?

1
vb6 is always 32bit I thought.. as a result running on 64bit or not, its 32bit. - BugFinder
Yes, unless the op actually means VBA. Even if not, I think this question needs more detail, at least show what has been tried, relevant working example that brings up the issue, the error codes, etc. - acelent
Try to run it as "c:\windows\syswow64\cscript.exe" myScript.vbs - MC ND
@MCND I have tested with cscript and wscript from the Syswow64 folder, both yielded the same results, in fact, the script does not even run if not with either of those 2. - Xtr
On top of @MCND suggestion are you running them with elevated privileges? - user692942

1 Answers

0
votes

Here's the deal. Applications written from VB6 are 32-bit. Your application works on 32-bit Windows and from a VB6 app on Windows 64 (which is running as 32-bit, since VB6 produces 32-bits. So, we know that your DLL works with 32-bit applications.

The thing is, when you run a VB script on Windows 64, it runs as a 64-bit process and you have a mismatch with your 32-bit DLL. If you run the VB script with the 32-bit version of the VB script engine (c:\windows\syswow64\wscript.exe or c:\windows\syswow64\cscript.exe) does it work? It probably will.

Now, if you compiled your DLL with the AnyCPU processor setting, then you can still register your DLL and get it to work with a 64-bit process. Just be sure to use the regasm.exe that is in the 64-bit hive.

For example register your DLL as such,

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm.exe /tlb /codebase c:\path\to\yourdll.dll