2012-06-04 3 views
0

다음은 이전 질문에 대한 후속 작업입니다. 일부 Vb.net 코드를 C#으로 변환하려고합니다. com 객체가 만들어지고 (atlDirectorObject.atlDirector) 매개 변수별로 다른 com 객체 (atl3270Tool)를 만드는 데 사용됩니다. atl3270Tool이 C# 버전에서 생성되지 않습니다. 객체 배열을 통해 atl3270Tool을 참조하려고 시도하는 잘못된 경로가 있습니까?C에서 다른 com 객체를 사용하여 com 객체 만들기

'working vb code 
Dim atl3270Tool 
Dim ErrMsg As String 
Dim atlDirectorObject = CreateObject("atlDirectorObject.atlDirector") 
atlDirectorObject.CreateTool("3270", 1, True, True, 0, atl3270Tool, ErrMsg) 
'atl3270Tool is working com object at this point = success 

//non-working c# code 
object atl3270Tool = null; 
string ErrMsg = null; 
object atlDirectorObject = Activator.CreateInstance(Type.GetTypeFromProgID("atlDirectorObject.atlDirector")); 
//atlDirectorObject is a com object now 
//attempt to reference atl3270Tool inside an object array 
object[] p = { "3270", 1, true, true, 0, atl3270Tool, ErrMsg }; 
Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateCall(atlDirectorObject, null, "CreateTool", p, null, null, null, false); 
//>>>>>>>>atl3270Tool is still null at this point<<<<<<<<< 
+0

예, 잘못하고 있습니다. 호출 후 atl3270Tool = p [5] *를 사용하십시오. CopyBack 인수를 사용해야합니다. 이 코드를 작성하기 위해 vb.net을 사용하라는 권고를 받았을 때 나는 분명히 * 그 *를 의미하지는 않았습니다. –

답변

0

한스가 맞습니다. vb.net에서이 작업을 수행하는 것이 가장 좋습니다. 그러나 C#에서 이렇게하기로 결심 한 사람들은 다음과 같습니다. 해결책 :

object atl3270Tool = null, ErrMsg = null; 
    object atlDirectorObject = Activator.CreateInstance(Type.GetTypeFromProgID("atlDirectorObject.atlDirector")); 
    object[] p = { "3270", 1, true, true, 0, atl3270Tool, ErrMsg }; 
    object[] p2 = { "xxxx", "", "xxxxxxxxxx", ErrMsg }; 
    Boolean[] cb = new Boolean[7]; 
    cb[5] = true; //set array index of atl3270Tool to true 
    Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateCall(atlDirectorObject, atlDirectorObject.GetType(), "CreateTool", p, null, null, cb, false); 
    atl3270Tool = p[5]; 
    Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateCall(atl3270Tool, atl3270Tool.GetType(), "ShowScreen", p2, null, null, null, false); 
// add code to release com objects 
+0

좋아, 더 문제가있다. newlatebinding.latecall 메서드를 사용하여 복사 할 때 "atl3270Tool"(동일한 개체를 사용하여 내가 만든)을 사용하여 매개 변수의 일부 데이터를 가져 오는 중입니다. 내가 2 개의 매개 변수에 copy back = true를 넣으면 실패합니다 ("잘못된 호출 수신자 (HRESULT의 예외 : 0x80020010 (DISP_E_BADCALLEE))"). 다른 3 개의 매개 변수 중 하나를 true로 설정하면 오류가 발생하지 않습니다. 한스, C#에서이 일을 주장하면서 나에게 너무 좌절하지 않는다면. 나는 어떤 방향에 감사 할 것입니다. – Theo

+0

ScreenText는 string.empty가 아니라 null이어야합니다. – Theo