Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BS2_SetIPConfigを理解したいがエラーで困っています #18

Closed
tenpotech opened this issue Feb 15, 2022 · 1 comment
Closed

Comments

@tenpotech
Copy link

Suprema 担当者様へ

いつもお世話になっております。

SFApi.csファイルに含まれる

[DllImport("BS_SDK_V2.dll", CallingConvention = CallingConvention.Cdecl)]
extern public static int BS2_SetIPConfig(IntPtr context, UInt32 deviceId, ref BS2IpConfig config);

のBS2_SetIPConfigの第3引数でコンパイルエラーが起きて回避できません。

理由を御社のTicketSiteで質問しましたが、一方的にTicket Closeされました。

BS2IpConfig bs2IpConfig = new BS2IpConfig();
bs2IpConfig.ipAddress = Encoding.ASCII.GetBytes("192.168.0.123");
result = (BS2ErrorCode)API.BS2_SetIPConfig(context, deviceID, ref bs2IpConfig);

のようにやっても、エラーになります。

Unhandled exception. System.ArgumentException: Type could not be marshaled because the length of an embedded array instance does not match the declared length in the layout.
at System.StubHelpers.MngdFixedArrayMarshaler.ConvertSpaceToNative(IntPtr pMarshalState, Object& pManagedHome, IntPtr pNativeHome)
--- End of stack trace from previous location ---
at Suprema.API.BS2_SetIPConfig(IntPtr context, UInt32 deviceId, BS2IpConfig& config)
at Biostar2SDKTest.Program.Main(String[] args)

Ticketで質問したら、C++構造体だと言われて

IntPtr pStructure = Marshal.AllocCoTaskMem(Marshal.SizeOf(bs2IpConfig));
Marshal.StructureToPtr(bs2IpConfig, pStructure, false);

Marshal.FreeCoTaskMem(pStructure);

のように、追加してみても、結局エラーになります。
改善策を提示してください。
宜しくお願いします。

ConfigControl.csのSetIPConfigを使う方法は動作するのに、BS2_SetIPConfigは何故動作しませんか?
教えてください。

@tenpotech
Copy link
Author

I self-solved the problem with the BS2IpConfig structure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant