How to call a function from .dll file

Hello World,

Recently, my boss asked me: Can Visual Components use a .dll file?
So, I found this article: Import a C DLL into Visual Components.

To be honest, I’m not very experienced with this topic, so I just followed the steps and tried to reproduce what the author did.

I opened a new Class Library using .NET Framework 4.7.2 (I wasn’t sure which version to use, so I went with the default suggestion) and added UnmanagedExports v1.2.7.
However, it failed and I got the following error messages:

Then, I tried creating a new Class Library with .NET Standard (.NET 8.0) and added the same UnmanagedExports v1.2.7. Although it showed a partial incompatibility warning, at least I was able to generate a .dll file:

However, VC still won’t accept it :disappointed_face: — it cannot find the function name, unlike what the author demonstrated.
No matter where I place the .dll file, it still doesn’t work.

## VC OUTPUTS
Traceback (most recent call last):
  File "Sphere Geo (Ball)::PythonScript", line 10, in OnRun
  File "C:\Program Files\Visual Components\Visual Components Professional 4.10\Python 2\Lib\ctypes\__init__.py", line 366, in __getattr__
    func = self.__getitem__(name)
  File "C:\Program Files\Visual Components\Visual Components Professional 4.10\Python 2\Lib\ctypes\__init__.py", line 371, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'TestExport' not found

Is anyone able to give me some tips about import DLLs or point me to a learning path? I’d really appreciate it!

Hi,

Can you test by adding “Plugin.” prefix to your dll name?

e.g. foo.dll –> Plugin.foo.dll

Please also see this academy video:

1 Like

Dear Lefa,
Thank you for your reply.

I tried your suggestion of renaming the file with the “Plugin” prefix, but it seems that was not the issue.

However, I was able to fix the DllExport unexpected error:
System.ArgumentException: Requested value 'Version47' was not found.
The solution was to install Microsoft Build Tools 2015, as mentioned here: (Failing to compile in VS 2017 · Issue #29 · 3F/DllExport)

I think the problem was that I didn’t properly create an unmanaged DLL file.
Now, I can successfully import the DLL into a component using a Python script behavior.

Next, I would like to look into the plugin topic in the Academy as you suggested :slightly_smiling_face:.

1 Like