04-06-2011 04:46 AM
Hello,
I want to address a OMICRON CPC100 device via remote control. I have a dll ("TESTCONTROL.dll"), which provides methods to control the CPC100. In order to encapsulate this functionality, I've written a VB.NET-dll ("CLC_CL_for_Net.dll") (it's a class-dll) which calls methods of TESTCONTROL.dll. Now I want to use CLC_CL_for_Net.dll in LabVIEW.
Here's the code of CLC_CL_for_Net.dll:
Imports TESTCONTROLLib
Namespace MyCPCNamespace
Public Class CPCClass
Public Sub New()
End Sub
Public Sub testfunction(ByVal ipaddress As String)
Dim tc As TestProcedure
Dim atm As IATMTest
tc = CreateObject("TestControl.TestProcedure", ipaddress) '<-- here the error occurs!
atm = CreateObject("TestControl.ATMTest", ipaddress)
'(...)
atm.Activate(300, 10, 1)
'(...)
atm.Deactivate()
End Sub
End Class
End Namespace
In order to enable DCOM on my computer, I did the following:
- I switched the firewall off.
- I started "dcomcnfg.exe", chose "Component Services/Computers/My Computer -> Properties" and checked the checkbox "Enable Distributed COM on this computer".
- I also chose the tab "My Computer Properties/COM Security" and allowed everyone full access and launch
permissions.
- I created an exe-file from my LabVIEW VI, which uses the dll, with the help of the LabVIEW Application Builder.
For this exe-file and also for the TESTCONTROL, I set the authentication level to "None".
For test purposes, I used my dll in a C++ project. There everything works fine. However, when I try to use the dll
in LabVIEW (using LabVIEW's .NET constructor node and method node, which you can find under Connectivity -> .NET), the program fails at the line "tc = CreateObject("TestControl.TestProcedure", ipAddress)".
Here the error message displayed by LabVIEW (I translated it from German into English):
"Error 1172 has occurred at Error calling method CLC_CL_for_Net.MyCPCNamespace.CPCClass.testfunction of ObjectId
handle: 0x2BB117C for obj 0x3F19E1D[CLC_CL_for_Net.MyCPCNamespace.CPCClass] in domain [LabVIEW Domain for Run] and
thread 3792, (System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
Inner Exception: System.Exception: The ActiveX component cannot be created.
) in CPC100_RemoteControlVI.vi"
As the dll works when I use it in the C++ project, I don't understand why this error occurs when I use the dll in
LabVIEW. Do I have to give LabVIEW any special permissions?
Can anyone help me to solve this problem? Thanks a lot for your efforts!
Regards,
Matthias
04-07-2011 04:10 AM
Now I inserted the line "ole.AuthnLevel=1" into the file "LabVIEW.ini". The result is that the program doesn't fail at "tc=CreateObject(...)" or "atm=CreateObject(...)" any more, but one line below when the object "atm" is to be used the first time. 😞
Has anyone an idea why this happens? Thanks very much!
Regards, Matthias
04-08-2011 02:28 AM - edited 04-08-2011 02:29 AM
Hi Matthias,
I am not really familiar with .NET assemblies but I found couple informations on your error :
First of all, about the Error 1172 in LabVIEW, there is two things to proof:
Those two steps sometimes solve Error 1172 related problems. I also found some information about the "ActiveX component cannot be created" error. A .Net Class library needs to be in a COM wrapper in order for it to be called through COM methods, such as ActiveX. The way to do so is:
1. Create a new .NET Class Library project.
2. Remove the Class1.vb that is created.
3. Click Add Class on your project.
4. Choose "COM Class", and add it.
5. Add at least 1 function or sub in it.
6. Compile it, and Visual Studio should registrer it automaticly.
If you whish to manuall reg it, or create a registry entry file, use "RegAsm.exe" in the .NET Framework folder.
I hope this could be any helpful to you
Regards
04-08-2011 06:39 AM
Hello Mr Abry,
thank you for your answer. You recommended me to add the .Net assembly as a reference in LabVIEW. Unfortunately, I don't find the menu item "Tools->Advanced->NET Assembly References". (I'm using LabVIEW 8.5, the German version.) I tried "Werkzeuge->Import->.NET-Elemente zur Palette", but this didn't work. The error message was: "Diese Assembly enthält keine öffentlichen Elemente."
Is there another possibility to make the dll known to LabVIEW? And what about the dll "TESTCONTROLLib.dll"? Should I also add a reference to it to LabVIEW? Actually, this dll is used directly only by the .NET-dll "CLC_CL_for_Net.dll". But as the program fails exactly at the line where functionality of TESTCONTROLLib is used the first time, I think there could be a problem with this dll...
Regards, Matthias
04-08-2011 08:33 AM
HI matthias,
"Tools => Import => .NET Control or Palette" is supposed to be the right one (I found out too late that the Tool => Advanced path was for older versions of LabVIEW).
I'm definitivly not a .NET expert, but the way you describe it makes me also think there could be a problem yith the DLL. Could you compile it again?
I didn't found any explications so far for the last error you get.
Regards
04-08-2011 09:05 AM
Unfortunately, compiling and building the dll again didn't solve the problem. It still causes the message "Diese Assembly enthält keine öffentlichen Elemente" when I try to add the dll as a reference to LabVIEW.
But meanwhile, I think that not the .NET-dll itself causes the failure, but the dll "TESTCONTROLLib" which is called in the .NET-dll. (For test purposes, I wrote another .NET-dll which did not call "TESTCONTROLLib", and this one worked fine in LabVIEW. I didn't even have to add it as a reference; it was enough to place a .NET constructor node on my VI and choose the dll in the properties of the node.)
So, perhaps TESTCONTROLLib has to be registered somewhere or has to be granted special permissions? Maybe there is even a permission for a dll to call another dll or to set up remote connections?
Thanks a lot for your effort!
Regards, Matthias
04-13-2011 02:53 AM
Now I managed to solve my problem: I opened the file "LabVIEW.ini" and added the line "ole.AuthnLevel=1". After a reboot it worked fine.
Thanks to Florian Abry for your help!
04-13-2011 05:27 AM
Hi,
Thanks for notifying it is now solved. It's weird that it didn't worked the first time you tried this solution.
Cheers