Passing a structure from c++ into a LIB written in c# using Framework 4.0

  • Thread starter Thread starter Jeff Purdue
  • Start date Start date
J

Jeff Purdue

Guest
I don't know much about c#, but I need to create a c# lib that can be called from c++. The functions in c# need to receive a structure of data. My code is listed below:

c++ (LIB is included in project)

struct Name
{
char FileName[100];
char FileVersion[100];
};
Name;

Name szFile;

VisionScape Vs;
Vs.LoadCameraWithConfigFile( szFile);

c# LIB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;

namespace MicroScanFrontRunner
{
public class VisionScape
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct Name
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
public string FileName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
public string FileVersion;
};

public int LoadCameraWithConfigFile( Name sName )
{
int value;
value = 2;
return value;
}
}
}

I am getting the following compiler error:

Severity Code Description Project File Line Suppression State
Error C2664 'int MicroScanFrontRunner::VisionScape::LoadCameraWithConfigFile(MicroScanFrontRunner::VisionScape::Name)': cannot convert argument 1 from 'InitializeScanner::Name' to 'MicroScanFrontRunner::VisionScape::Name' MicroScan C:\Users\efthss\Desktop\Plant Moves\MicroScan Vision\C dll\MicroScanCamreaGige\MicroScan.cpp 100

Continue reading...
 
Back
Top