我有一个 c++ 项目,它将调用一个 C# 函数,之后,c# 将调用一个 c++ 函数(两者都有返回值)。我卡在stackoverflow上有人给我的COM接口上(我对c++或c#没有太多经验,只有java),但由于某种原因,当我尝试编译C++代码时它给了我一个错误,致命错误C1196 : 'FaceTrackingBasics-WPF' : 在类型库 c:\FaceTrackingBasics-WPF/bin/x86/Debug/FaceTrackingBasics-WPF.tlb 中找到的标识符不是有效的 C++ 标识符。
你能发现一些错误吗?也许我不应该在一个文件中有两个类?顺便说一句,c# 代码与一个窗口相关联,我不知道它是否会导致问题。谢谢
C# 代码
// -------------------------------------------------------------------------------- ------------------------------------
// <copyright file="FaceTrackingViewer.xaml.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -------------------------------------------------------------------------------- ------------------------------------
namespace FaceTrackingBasics
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Microsoft.Kinect;
using Microsoft.Kinect.Toolkit.FaceTracking;
using System.Globalization;
/////
using System.Runtime.InteropServices;
using Point = System.Windows.Point;
/// <summary>
/// Class that uses the Face Tracking SDK to display a face mask for
/// tracked skeletons
/// </summary>
public partial class FaceTrackingViewer : UserControl, IDisposable
{
public static readonly DependencyProperty KinectProperty = DependencyProperty.Register(
"Kinect",
typeof(KinectSensor),
typeof(FaceTrackingViewer),
new PropertyMetadata(
null, (o, args) => ((FaceTrackingViewer)o).OnSensorChanged((KinectSensor)args.OldValue, (KinectSensor)args.NewValue)));
private const uint MaxMissedFrames = 100;
private Boolean drawFlat = false;
public FaceTrackingViewer()
{
this.InitializeComponent();
}
~FaceTrackingViewer()
{
this.Dispose(false);
}
public KinectSensor Kinect
{
get
{
return (KinectSensor)this.GetValue(KinectProperty);
}
set
{
this.SetValue(KinectProperty, value);
}
}
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
//i deleted the rest of the code, i dont think its relevant
}
}
//***********************//
[ComVisible(true)]
[Guid("2EF06BCB-A25B-41AD-B233-33A956DBEB69")]
public struct Ponto
{
public double x;
public double y;
public Ponto(double x, double y)
{
this.x = x;
this.y = y;
}
}
[ComVisible(true)]
[Guid("EB9258F5-DCFB-4F91-8342-5A05EB17557D")]
public interface IManagedClass
{
Ponto[] Foo();
}
[ComVisible(true)]
[Guid("11B23AD7-F79E-45D7-BC87-89F0DBC8B83F")]
[ClassInterface(ClassInterfaceType.None)]
public class ManagedClass : IManagedClass
{
private List<Ponto> points;
public ManagedClass()
{
points = new List<Ponto>();
points.Add(new Ponto(1.0, 1.0));
points.Add(new Ponto(2.0, 2.0));
points.Add(new Ponto(3.0, 3.0));
}
public Ponto[] Foo()
{
return points.ToArray();
}
}
c++代码
#include "stdafx.h"
#import "C:/Users/Pedro/Dropbox/0000000TESE/000_visual_studio/0FaceTMS/FaceTrackingBasics- WPF/bin/x86/Debug/FaceTrackingBasics-WPF.tlb"
#include <iostream>
using namespace FaceTrackingBasics;
using namespace std;
int main()
{
::CoInitialize(NULL);
{
IManagedClassPtr pManagedClass(__uuidof(ManagedClass));
SAFEARRAY* psa = pManagedClass->Foo();
Ponto* pPoints = (Ponto*)psa->pvData;
for (int i = 0; i < 3; ++i)
cout << pPoints[i].x << " " << pPoints[i].y << endl;
}
::CoUninitialize();
}