0
$\begingroup$

I have an application using DefineDLLFunction whose output is:

Function[Null, If[NETLinkDLLPrivatecheckArgCount["DRV_AOVoltageOut", {##1},2], WolframNETLinkDynamicDLLNamespaceDLLWrapper2DRVUAOVoltageOut[##1], $Failed], {HoldAll}]

How to extract the information “DynamicDLLNamespaceDLLWrapper2” from the output above?

$\endgroup$
4
  • 1
    $\begingroup$ Please make an effort on the formatting.. For space for a line of code, back ticks for inline code. ATM it is very ugly. $\endgroup$
    – Öskå
    Commented Jan 22, 2014 at 11:54
  • 2
    $\begingroup$ detailed info on formatting $\endgroup$
    – Wojciech
    Commented Jan 22, 2014 at 12:24
  • $\begingroup$ Part can probabl do it... $\endgroup$
    – Ajasja
    Commented Jan 23, 2014 at 20:57
  • $\begingroup$ Ajasja : Unfortunately this do not get what I want…If open1742 is my DefineDLLFunction, for open1742[[i]], i=0..4, I don’t obtain the requested information “DynamicDLLNamespaceDLLWrapper2” $\endgroup$ Commented Jan 24, 2014 at 15:45

1 Answer 1

6
$\begingroup$

This question was heavily edited to remove the (badly formatted) long preamble that explained the motivation. What the questioner is trying to do is call a DLL function with an argument whose type is dynamically defined in the call to DefineDLLFunction. To get the full name of this type programmatically, you need to extract the name of the dynamically-defined namespace from the function returned by DefineDLLFunction. This namespace is given by the context of the DRVUAOVoltageOut symbol, which is "Wolfram`NETLink`DynamicDLLNamespace`DLLWrapper2`" in the example (this got messed up a bit above because of bad formatting). The questioner wants to extract this context and use it to create the string name of the .NET type he wants to create to pass as an argument, which in this case will be "Wolfram.NETLink.DynamicDLLNamespace.DLLWrapper2+PT_AOVoltageOut".

Here is one way to do it. The original DefineDLLFunction call looked like this:

f = DefineDLLFunction["
       public class PT_AOVoltageOut
           {
              public ushort chan;
              public float OutputValue;
           }
       [DllImport(\"Adsapi32.dll\",CallingConvention = CallingConvention.StdCall,
                 CharSet = CharSet.Auto, SetLastError = true)]
       public static extern short DRV_AOVoltageOut( [In, Out] Int32 DriverHandle, PT_AOVoltageOut IntPtr);"
]

This returns the somewhat cryptic Function shown in the original question. To create the type name:

ctxt = Context[Evaluate @ First @ Cases[f, If[_, sym_[_], _] :> sym]];
typeName = StringDrop[StringReplace[ctxt, "`" -> "."], -1] <> "+PT_AOVoltageOut";

Then, to create an object:

voltageOut = NETNew[typeName]
$\endgroup$
1
  • 1
    $\begingroup$ This works wonderful! I can't avoid: Many thanks!! I apologize for the gently said “long preamble” of my question. I ought to remember the words of Werner Heisenberg: “the measure to which someone expresses something in simple words is a measure of the level of knowledge reached”. I will try in the future to better apply this saying to my questions and comments. $\endgroup$ Commented Jan 25, 2014 at 7:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.