2017-08-24 1 views
0

ごく基本的な質問には申し訳ありません。 UNCパスを文字列で置き換えたかっただけです。 CのためのUNCパスを有するこれらの行++接続は、完全に動作:「オブジェクト参照が非静的フィールド、メソッド、またはプロパティのために必要とされる」文字列でUNCパスを交換UNCパスを文字列で置き換えようとするとエラーが発生する

[DllImport(C:\\Users\\SJ\\Documents\\VS2015\\Projects\\P_01\\Debug\\EV_01.dll", 
EntryPoint = "DDentry", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] 
public static extern void DDentry 
(
    [MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_BSTR)] 
    string[,] pArrayStr 
); 

がエラーを与える

あなたのアイデアを
string UNCpath = @"C:\\Users\\SJ\\Documents\\VS2015\\Projects\\P_01\\Debug\\EV_01.dll"; 

[DllImport(UNCpath, 
EntryPoint = "DDentry", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] 
public static extern void DDentry 
(
    [MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_BSTR)] 
    string[,] pArrayStr 
); 

多くの感謝...

+0

[変数値を持つカスタム属性をパラメータとして渡す]可能な複製(https://stackoverflow.com/questions/13125046/passing-a-custom-attribute-with-a-variable-value-as- a-parameter) – Diado

答えて

1

は、あなたはそのような属性にインスタンス値UNCPathを渡すことはできません。それは定数である必要があります。また、二重バックスラッシュエスケープシーケンスを使用する場合は、文字列に接頭辞@を使用できません。

これを試してください:あなたは、属性と非文字列定数を使用しようとしていると、それが許可されていない

const string UNCpath = "C:\\Users\\SJ\\Documents\\VS2015\\Projects\\P_01\\Debug\\EV_01.dll"; 

[DllImport(UNCpath, 
EntryPoint = "DDentry", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] 
public static extern void DDentry 
(
    [MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_BSTR)] 
    string[,] pArrayStr 
); 
+2

別の言い方をすれば、 '@ '接頭辞を使用する場合、バックスラッシュをエスケープする必要はありません。 – stuartd

+0

働いて..ありがとう。 – Sepp

0

。文字列を "const"として宣言する必要があります。

関連する問題