Tôi muốn gọi hàm GetIdsOfNames từ đối tượng COM thực hiện giao diện IDispatch trong C#. Tôi đã viết mã sau nhưng nó không thành công với DISP_E_UNKNOWNNAME. Đây có phải là cách tiếp cận chính xác để thực hiện việc này không?Gọi một thành viên của giao diện IDispatch COM từ C#
Object so = Activator.CreateInstance(Type.GetTypeFromProgID("ProgID"));
Object[] args = new Object[5];
string[] rgsNames = new string[1];
rgsNames[0] = "PrintNormal";
uint LOCALE_SYSTEM_DEFAULT = 0x0800;
uint lcid = LOCALE_SYSTEM_DEFAULT;
int cNames = 1;
int[] rgDispId = new int[1];
args[0] = IntPtr.Zero;
args[1] = rgsNames;
args[2] = cNames;
args[3] = lcid;
args[4] = rgDispId;
Object result = so.GetType().InvokeMember("GetIDsOfNames", BindingFlags.InvokeMethod, null, so, args);
Cảm ơn,
Richard
cảm ơn. Thats thực sự thực sự hữu ích. –