Calling dll funtions

Hello, I decided to learn Julia in order to automate some data analysis and some experiments in the Lab, still, I am struggling with some simple things…

I am trying to call a couple of functions of a DLL file in order to interact with a spectrometer.
I was provided with an executable file that tests the dll functions, however, I would like to port this to Julia.

in the cpp file of this executable,

	int *connect = classSpec::Connect();
	if (connect[0] == 0)
		cout << "Connection failed!!!" << endl;
		if (connect[1] == 0)//STD
			cout << "spec std  connected!!!" << endl;
			nPixel = 2048;
			if (connect[1] == 1)//RES+
			cout << "spec res+ connected!!!" << endl;
			nPixel = 3648;

This returns an array wherein the first position we know if the connection was successful and in the second array the type of equipment.

In order to reproduce this, I suppose I should use ccall

connect =ccall(("function_name","libfile"), Ptr{Int32}, () )

and later on


However, when I do this I can only access the status of the connection (1st position).

Any directions on how to proceed would be of great use,
thanks in advance.


Since you are returning an array, try this

const CONNECT_SIZE = 2
connect = ccall((:function_name, "libfile"), stdcall, Ptr{NTuple{CONNECT_SIZE,Int32}}, ())
connect_ = unsafe_load(connect)
# then you will have to convert the NTuple to Array
connect_arr = collect(connect_)

Try to write your code between ``` like this

some julia code
`` `< remove the space
or c++
some c++ code
`` `< remove the space
1 Like