# Calling dll funtions

**URL:** https://discourse.julialang.org/t/calling-dll-funtions/25301
**Category:** General Usage
**Created:** [June 14, 2019, 10:39am UTC](https://discourse.julialang.org/t/calling-dll-funtions/25301 "2019-06-14T10:39:25Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![rjsharp](https://avatars.discourse-cdn.com/v4/letter/r/4bbf92/32.png) [@rjsharp](https://discourse.julialang.org/u/rjsharp)
#### Post date: [June 14, 2019, 10:39am UTC](https://discourse.julialang.org/t/calling-dll-funtions/25301/1 "2019-06-14T10:39:25Z")

</div>

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,

```julia
//CONNECT
	int *connect = classSpec::Connect();
	if (connect[0] == 0)
	{
		cout << "Connection failed!!!" << endl;
	}
		else
	{
		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

`unsafe_load(connect)`

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.

---

<div class="post-metadata">

### Author: ![gabrielfreire](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gabrielfreire/32/8799_2.png) [@gabrielfreire](https://discourse.julialang.org/u/gabrielfreire)
#### Post date: [June 14, 2019, 1:00pm UTC](https://discourse.julialang.org/t/calling-dll-funtions/25301/2 "2019-06-14T13:00:35Z")

</div>

Hi,

Since you are returning an array, try this

```julia
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

````nohighlight
```julia
some julia code
`` `< remove the space
or c++
```cpp
some c++ code
`` `< remove the space

````
