# Custom gh compounent calls a c++ writen dll , rhino crash?

**URL:** <https://discourse.mcneel.com/t/custom-gh-compounent-calls-a-c-writen-dll-rhino-crash/65053>\
**Category:** Grasshopper Developer\
**Created:** [June 14, 2018, 3:21am UTC](https://discourse.mcneel.com/t/custom-gh-compounent-calls-a-c-writen-dll-rhino-crash/65053 "2018-06-14T03:21:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![1219320762](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/1219320762/32/103555_2.png) [@1219320762](https://discourse.mcneel.com/u/1219320762)\
**Post date:** [June 14, 2018, 3:21am UTC](https://discourse.mcneel.com/t/custom-gh-compounent-calls-a-c-writen-dll-rhino-crash/65053/1 "2018-06-14T03:21:43Z")

</div>

i write a c# console to invoke this dll. it works well. but when i invoke this dll in gh , it makes rhino crash.  
here is my c++code.

```auto
array<int>^ SAP::recogMarkerID(System::String ^path)
{
	std::string p = msclr::interop::marshal_as<std::string>(path);

	cv::Mat img = cv::imread(p, 1);

	std::vector<cv::Point2f> pts;
	std::vector<int> IDD;
	std::vector<int> IDDD;

	cSAp->recogMarkers(img, pts, IDD);
	std::vector<int> coordinates;

	if (pts.size() != 0)
	{

		for (size_t i = 0; i < IDD.size(); i++)
		{
			coordinates.push_back(IDD[i]);
			
		}
	}
	array<int>^cc = gcnew array<int>(coordinates.size()+1);;
	for (size_t i = 0; i < coordinates.size(); i++)
	{
		cc[i] = coordinates[i];
	}
	cc[coordinates.size()] = -1;
	
	return cc;
}

```

and this how i invoke in c# or gh

```auto
float[] p = new float[1];
  p = SS.recogMarker(path);

```

---

<div class="post-metadata">

**Author:** ![DavidRutten](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/davidrutten/32/755688_2.png) [@DavidRutten](https://discourse.mcneel.com/u/DavidRutten)\
**Post date:** [June 14, 2018, 7:45am UTC](https://discourse.mcneel.com/t/custom-gh-compounent-calls-a-c-writen-dll-rhino-crash/65053/2 "2018-06-14T07:45:26Z")

</div>

Is your SAP dll 32 or 64 bit?

---

<div class="post-metadata">

**Author:** ![gankeyu](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/gankeyu/32/487811_2.png) [@gankeyu](https://discourse.mcneel.com/u/gankeyu)\
**Post date:** [June 14, 2018, 7:52am UTC](https://discourse.mcneel.com/t/custom-gh-compounent-calls-a-c-writen-dll-rhino-crash/65053/3 "2018-06-14T07:52:08Z")

</div>

It looks like a managed C++ library. So it should be treated as `unchecked` and `unsafe` mananged code?

---

<div class="post-metadata">

**Author:** ![1219320762](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/1219320762/32/103555_2.png) [@1219320762](https://discourse.mcneel.com/u/1219320762)\
**Post date:** [June 15, 2018, 12:51pm UTC](https://discourse.mcneel.com/t/custom-gh-compounent-calls-a-c-writen-dll-rhino-crash/65053/4 "2018-06-15T12:51:18Z")

</div>

64bit, and this dll runs well in a c# console application

---

<div class="post-metadata">

**Author:** ![1219320762](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/1219320762/32/103555_2.png) [@1219320762](https://discourse.mcneel.com/u/1219320762)\
**Post date:** [June 15, 2018, 12:59pm UTC](https://discourse.mcneel.com/t/custom-gh-compounent-calls-a-c-writen-dll-rhino-crash/65053/6 "2018-06-15T12:59:38Z")

</div>

right ,it is a managed library.  
your " treated as `unchecked` and `unsafe` mananged code" is the way of call this dll in c# like the code below？  
unsafe  
{  
float[] p = new float[1];  
p = SS.recogMarker(path);  
}  
but what i am confused is that this code can run well in a c#console app, but crush in rhino.
