将固定长度的数组编组为从C ++到C#内部结构的指针

时间:2019-03-03 22:18:54

标签: c# marshalling

我想封送一些结构,该结构在C ++中包含诸如@Configuration public class CacheContext { @Bean @ConfigurationProperties("settings.cache") public CacheSettingsBean paymentCacheSettingsBean() { return new CacheSettingsBean(); } @Bean public Cache<String, Signal<? extends PaymentSettingsEntity>> paymentSettingsCache() { return Caffeine.newBuilder() .maximumSize(paymentCacheSettingsBean().getMaximumSize()) .expireAfterWrite(paymentCacheSettingsBean().getExpireAfterWrite()) .build(); } @Bean public CachedSettingsRepository<PaymentSettingsEntity> cachedPaymentSettingsRepository( SettingsRepository<PaymentSettingsEntity> paymentSettingsRepository, Cache<String, Signal<? extends PaymentSettingsEntity>> paymentSettingsCache) { return new CachedSettingsRepository<>(paymentCacheSettingsBean().getKey(), paymentSettingsRepository, paymentSettingsCache); } } 之类的字段,而与诸如@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = [CacheContext, TestContext]) @ActiveProfiles("settings-cache") @EnableConfigurationProperties class CachedSettingsRepositoryTest extends Specification { @Autowired CachedSettingsRepository<PaymentSettingsEntity> cachedPaymentSettingsRepository @Autowired SettingsRepository<PaymentSettingsEntity> paymentSettingsRepository def "test getting from cache"() { given: def paymentSettings = paymentSettingsEntity() when: def result1 = cachedPaymentSettingsRepository.get().block() def result2 = cachedPaymentSettingsRepository.get().block() then: 1 * paymentSettingsRepository.get() >> Mono.just(paymentSettings) 0 * _ result1 == paymentSettings result1 == result2 } def paymentSettingsEntity() { PaymentSettingsEntity.of([PaymentRangeSetting.of(0.0, 100.0)]) } @Configuration static class TestContext { private DetachedMockFactory factory = new DetachedMockFactory() @Bean SettingsRepository<PaymentSettingsEntity> paymentSettingsRepository() { factory.Mock(SettingsRepository) } } } 之类的东西一样,但封送处理由于异常而失败。

同时,如果我只创建3个单独的字段,例如const void *data[3],则封送处理将开始正常工作。但这看起来很丑。有没有办法在单个字段中编写它?

请帮帮我。这个问题使我发疯。

编辑 [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] IntPtr[] data

为例外

0 个答案:

没有答案