I will give you a brief description of my software before I ask questions.
So there is a front end C# code which provides the user interface and a back end C++ code that deals with the hardware.
The C# project creates an executable (.exe) file and the C++ project creates a DLL which talk with each other using pinvoke calls (import/export functions). All this worked fine on WEC7.
Now, we are moving to WEC2013 with Toradex. I downloaded the WEC2013 SDK from Toradex’s website and was able to port my code and build it on VS2013.
I copied all the required files on a USB and when I tried running it the C# exe is not able to communicate with the C++ Dll. The error I get is :
missingmethodexception can't find pinvoke dll “xyz.dll”
I have made sure the dll exists at the specified location. The dll also has the required export functions.
First I thought the function parameters in the export functions could be an issue, but I tried calling function which requires no parameter with the same result.
Any help will be really appreciated.
Related
I would like to use C\C++ generated DLLs in LabView, like this example or this one.
I am wondering if it deploys and runs the code on my target machine (my PXIe) or the DLL runs on the computer which is running LabView.
National instruments, in its using external codes in LabView page 15 under Characteristics of the Two Calling Approaches, mention that,
You compile the source code and link it to form executable code. If you
already have a compiled DLL, this step is not necessary.
LabVIEW calls the executable code when the Call Library Function
Node or CIN executes.
LabVIEW passes input data from the block diagram to the executable
code.
LabVIEW returns data from the executable code to the block diagram.
Which I believe it does not clarify whether or not the DLL runs on the target device, aka real-time.
Moreover, I found this document which was quite confusing since it did not refer to any specific method directly.
Side note: I need to run C/C++ code on PXIe and I need to call it from my LabVIEW code real-time.
I have never done this, so I can only try to give a few hints which might help:
If you want to use a dll, it must run on the target where your LabVIEW application runs: If your application runs on a desktop computer, the dll is accessed on the desktop computer. If your application runs on the PXI, the dll must run on the PXI.
Have a look at this NI website:
If the shared library is C++-based, National Instruments strongly
recommends using the MSVC 2009 or MSVC 2010 compilers.
and
If your DLL works on a Windows machine, it may work in LabVIEW
Real-Time (NI PharLap ETS). However, the code will fail if it calls
functions that are not included in the Real-Time operating system's
subset of Win32.
On this website they also have a tool which checks whether a specific dll will work.
I am working within a 32-bit ETL tool (Pervasive Data Integrator v9). I need to give this tool the ability to call an external function that will remove a file from within a ZIP archive without extracting the archive.
The ETL tool provides the ability to load an external DLL and call its functions. The DLL and its function gets referenced by ETL tool's custom script language like this:
Declare function OemToCharA lib "user32" (byval lpszSrc as string, byval lpszDst as string) as long
The function (OemToCharA in this example) is then called somewhere in the lines of the script that follow that declaration. I have tested this with a registered DLL and it works.
So I want to build a DLL with a function that will do the zip manipulation.
Since I don't know how to manipulate zip files programatically, I found DotNetZip - a free .NET class library that provides the heavy lifting for the zip archive operations. Problem for me is that it is .NET (managed). I would still like to try to use it. So I built a C# DLL (.NET 4.0) with a function that utilizes DotNetZip to do the required zip file manipulation. I pass in two parameters, "zip file location" and the "file to remove" and the zip archive gets updated.
I read about the idea of building a mixed-mode C++/CLI DLL to take advantage of managed .NET code in the native world. I found this VS solution which consists of 3 basic projects:
Managed (C#) DLL project
Mixed-mode C++ DLL wrapper project which references the C# DLL
A native (unmanaged) C++ console test app project which references the C++ wrapper
I built a test solution based on that pattern which removes a file from a zip archive and it works great. Please note however that the mixed mode DLL is called from a native C++ console app which is part of the VS solution. I didn't have to register any DLLs and it just works.
However ultimately I need the ETL tool to call the mixed mode DLL. I am not able to get this to work.
Things I have tried on the ETL server thus far:
I tried to register the mixed-mode wrapper DLL but SysWow64\regsvr32 fails to find an entry point in the DLL.
I installed VS 2015 VC++ x86 and x64 redistributable libraries on the ETL server.
I placed the DLLs from my solution (i.e., the mixed mode, c# and dotnetzip dlls) in the ETL engine folder because the console app worked when the DLLs were in its deploy folder.
The ETL tool has the ability to call an external application so I believe I could let it call a console app similar to my VS test solution but I'd really like to get this to work with only the DLLs. Is this possible? If so, what am I missing?
Kudos to Matt, thanks for the hint to use Process Monitor.
ETL tool was not finding the DLL but Process Monitor told me the folders it was checking...I moved the DLLs to one of the checked folders
My wrapper function was originally void with an output parameter for the return value - that was causing issues as I didn't have a good example in the ETL documentation of how to call a void function. I changed the function to return a "long" and removed the output parameter.
After making those two changes it started working. Thanks again Matt!
I am programming an application in Python which has to use some DLLs originally created from C# code. Generally the usage of such DLLs is working (proven with multiple DLLs, all from the same source). For deployment on other people computers I'm using Py2Exe which also works as intended.
But now I want to use another DLL and have the following problems. If I start the programm and make a call to a function within the DLL, it throws an error saying:
.Net Dll broken because of possibly missing native Dlls.
Now comes the strange part. If I compile the python program into an executable the message does not show up and everything works as intended.
I already tried to identify missing DLLs by comparing the DLL assembly with the ProcessExplorer but they look totally the same. Next thing was to try to set path variables to all Dlls which I am calling directly but this was no solution too.
Other informations which could be interesting are IDE and OS: I'm using Eclipse Indigo with PyDev 2.5 plugin on a Windows 7 machine.
So are there any things I could have overseen or settings which I could try to make it work?
Any suggestions are appreciated.
I took a program written in C/C++ and modified it's main function to accept some arguments as input and return a variable as output and created a Win32 DLL out of it. I then created a .NET DLL which uses InterOp to access the first DLL. Now when I load the .NET DLL in my C# app I get a System.DllNotFoundException from the DLL which is really baffling me as there were never memory issues with the program and both Win32/.NET dlls are located in the same directory (apart from modifying the main function, the code has not really changed).
The solution was provided in this thread, which was my original question some time ago. I'm pretty sure that answer is correct but I'm just missing something.
You can download my VS solution Here. The solution contains three projects: the Win32 DLL, the .NET DLL, and a winform app that references the .NET DLL (but when trying to test gives the DLL exception). Any help or debugging guidance would be greatly appreciated.
UPDATE: I have tried all the tips/suggestions below but I still get the exact same error. If it makes things easier, my VS solution is available to download in the hyperlink above.
Make sure you have placed the win32 dll on /windows/system32 folder(if only the dll name is passed to DllImport)
Alternatively you can also pass the full path of the dll to the DllImport Attribute.
Use a tool such as Dependency Walker to make sure you are not missing out on any dependent assembly.
I've written a .dll in C# to change the permissions on a folder. I also wrote an .exe to test the .dll and it successfully changes the permissions. Now I'm trying to call the .dll from ColdFusion, but I'm getting an error about System/Security/IPermission not being found.
I'm assuming this is an interface in C# that ColdFusion can't find in any of the available assemblies on my system. I've added the System.Security assembly to my References in the C# project. Is there something else I need to do to make sure ColdFusion can find the interface?
Here's how I'm using the .dll:
<cfobject type="dotnet" name="permObj" assembly="#pathToDLLs#CoursePortal.dll" class="CoursePortal.Permissions">
<cfset permObj.revokePermissions(dir, username)>
I never could get it to work. I switched the DLL to an EXE and used <cfexecute> to call it. It's working fine now. The .NET code is called so infrequently it doesn't make much difference that it's a separate app.