LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

.net controller in a CVI DLL

I've created a .net controller and can use it in a CVI executable but when I use it in a CVI DLL project and call the DLL from TestStand I get an error message. See Attachment.
 
Here is the main dll code:
 
#include "ProcessSupportCVI.h"  
#include <utility.h>
#include <cvirte.h>  

/* Needed if linking in external compiler; harmless otherwise */
int __stdcall DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    int rtn = 1;
   
    switch (fdwReason) {
        case DLL_PROCESS_ATTACH:
            if (InitCVIRTE (hinstDLL, 0, 0) == 0)    /* Needed if linking in external compiler; harmless otherwise */
                rtn = 0;    /* out of memory */
            break;
        case DLL_PROCESS_DETACH:
            CloseCVIRTE ();    /* Needed if linking in external compiler; harmless otherwise */
            break;
    }
   
    return(rtn);
}
int __stdcall DllEntryPoint (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    /* Included for compatibility with Borland */
    return DllMain (hinstDLL, fdwReason, lpvReserved);
}

__declspec(dllexport) void test(void)
{  
 ProcessSupport_KillProcess  Handle;
 int rtn;
 
 Initialize_ProcessSupport (); 
 ProcessSupport_KillProcess__Create (&Handle, NULL);
 ProcessSupport_KillProcess_KillProcessByName (Handle, "Notepad", &rtn, NULL); 
 Close_ProcessSupport ();
}
 
 
0 Kudos
Message 1 of 6
(4,131 Views)
This is most probably because the assembly is not in the global assembly cache (GAC) or the directory of the hosting process - in your case TestStand. If the target assembly is not supposed to be in the GAC, then you should either put it in the directory of the process, or you can register the assembly path by calling CDotNetRegisterAssemblyPath before calling any functions in the generated assembly wrapper. In your case, calling CDotNetRegisterAssemblyPath is probably the desired solution.
0 Kudos
Message 2 of 6
(4,114 Views)

I've already thought of the adding the assembly to GAC which didn't help but, I'll try your second suggestion to see if that helps.

Thanks,

Steve

0 Kudos
Message 3 of 6
(4,109 Views)

Not all assemblies can be added to the GAC. For one, the assembly has to be signed before it can be added to the GAC. May be registering your assembly in the GAC failed for this or some other reason. If your assembly is in the GAC, then I would expect the CVI .NET wrapper to be able to load it independent of where the calling executable is located.

When calling CDotNetRegisterAssemblyPath, make sure you pass the same string value as the __assemblyName constant in the generated source file. If you pass a different form of the assembly name, CVI will not be able to locate the assembly in subsequent calls to CDotNetLoadAssembly.

Message 4 of 6
(4,104 Views)
This simple assembly (that I built for testing purposes) was built and given a strong signature and then succefull added to the GAC. Again the exe worked and the dll didn't. I have a 10:00 meeting but, I try your second suggestion and get back to you after lunch with the results. Maybe, after adding to GAC, is it required to rebuild the wrappers using the CVI wizard again?
 
Thanks,
Steve
0 Kudos
Message 5 of 6
(4,101 Views)
Second suggestion worked much better.
 
Thanks,
Steve
0 Kudos
Message 6 of 6
(4,092 Views)