Failure to add msrdp.ocx control to C#.NET or VB.NET form.

B

Bill Struve

Need: Auto-logon to a terminal server, start a program, and, when the user
is quits the program, auto-logoff.

Problem: When msrdp.ocx is added to the Toolbox, attempting to draw the
control on the form gives the following "Microsoft Development Environment"
message:

"Compiler errors occured when generating a Windows Forms wrapper for ActiveX
control 'AxMSTSCLib'. Source code saved in '...AxInterop.MSTSCLib.cs'.
c:Documents and Settings\struvew\Local
Settings\Temp\8rzmsoz_.0.cs(493,24):error CS0037: Cannot convert null to
'MSTSCLib.AutoReconnectContinueState' because it is a value type
c:Documents and Settings\struvew\Local
Settings\Temp\8rzmsoz_.0.cs(1282,24):error CS0037: Cannot convert null to
'MSTSCLib.AutoReconnectContinueState' because it is a value type"

Note that I can find no files like "c:Documents and Settings\struvew\Local
Settings\Temp\8rzmsoz" either before, during, or after the above error
message.

There is a similar message from either VC.NET or VB.NET, and the control
never appears on the form.

My workaround has been to use VB6, since the control can be drawn on a VB6
form with no problem. The following code is then used to satify the "Need"
above:

Private Sub Form_Load()
MsRdpClient.DesktopHeight = Screen.Height / Screen.TwipsPerPixelY
MsRdpClient.DesktopWidth = Screen.Width / Screen.TwipsPerPixelX
MsRdpClient.FullScreen = True
UsersForm.Height = (MsRdpClient.DesktopHeight + 30) *
Screen.TwipsPerPixelY
UsersForm.Width = MsRdpClient.DesktopWidth * Screen.TwipsPerPixelX
MsRdpClient.Height = MsRdpClient.DesktopHeight * Screen.TwipsPerPixelY
MsRdpClient.Width = MsRdpClient.DesktopWidth * Screen.TwipsPerPixelX
MsRdpClient.Server = "PC07405"
MsRdpClient.UserName = "******"
MsRdpClient.Domain = "PC07405"
MsRdpClient.AdvancedSettings2.ClearTextPassword = "******"
MsRdpClient.SecuredSettings.StartProgram = _
"D:\\Projects\\RMOnlineQuotes\\bin\\RunApplication.exe
RMAdministrativeTools.exe"
MsRdpClient.FullScreen = True
MsRdpClient.Connect
End Sub

Note that I changed the user name and password to ***** after pasting into
this.

After making the VB6 executable, I call it from C#. Although this works OK,
it is UGLYto have to write part in C# and part in VB6.

Is there anyting I can do so the auto-generated "Windows Forms wrapper" will
complete without error?
 
S

Stephan Steiner

I wrote my own C# RDP client based on the ocx.

I only added the ActiveX component in code rather than graphically, but that
worked out nicely. There's just one thing.. I don't get any events thrown
from the control for some wicked reason.. I have the listeners properly set
up, but if the user logs off, the control just turns white and the window
never closes (the listener for the disconnect event would close the window,
but since it's never fired).

I don't have access to the code right now, but if you're interested, I can
post the relevant lines for you later on.

Regards
Stephan
 
K

Kevin Yu [MSFT]

Hi Bill,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that when you have drag and drop a Terminal
Services Control on a windows form, a compiler error was generated. If
there is any misunderstanding, please feel free to let me know.

Based on my research, this is a known issue. The wrapper generater fails to
generate correct method for returning an enum value. Here is a workaround.

1. md c:\temp
2. cd c:\temp
3. %<SDK bin directory>%\aximp.exe %windir%\system32\mstscax.dll
This will generate MSTSCLib.dll and AxMSTSCLib.dll.
Make sure Interop.MSTSCLib.dll and AxInterop.MSTSCLib.dll have been deleted
in the obj and bin\Debug directories.
4. Copy the generated files (without renaming) - MSTSCLib.dll and
AxMSTSCLib.dll into the project's obj directory.
5. In the project's references, add MSTSCLib.dll and AxMSTSCLib.dll from
the obj directories.
6. Now, instead of drag-drop'ing the control from the toolbox, write code
to add the control:
Goto Form.cs code view
Declare: private AxMSTSCLib.AxMsTscAx axMsTscAx1;
In InitializeComponent:
this.axMsTscAx1 = new AxMSTSCLib.AxMsTscAx();
((System.ComponentModel.ISupportInitialize)(this.axMsTscAx1)).BeginInit();

//
// axMsTscAx1
//
this.axMsTscAx1.Enabled = true;
this.axMsTscAx1.Location = new System.Drawing.Point(58, 17);
this.axMsTscAx1.Name = "axMsTscAx1"
this.axMsTscAx1.OcxState =
((System.Windows.Forms.AxHost.State)(resources.GetObject("axMsTscAx1.OcxStat
e")));
this.axMsTscAx1.Size = new System.Drawing.Size(192, 192);
this.axMsTscAx1.TabIndex = 1;
....

this.Controls.Add(this.axMsTscAx1);
((System.ComponentModel.ISupportInitialize)(this.axMsTscAx1)).EndInit();

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top