Hello everyone,
can someone help me understand the problem to the following situation:
I have written a little test addin for Solidworks PDM.
First of all the code:
This is my Main.cs:
using EPDM.Interop.epdm;
using System;
using System.Runtime.InteropServices;
namespace MyTestAddin
{
[ComVisible(true)]
[Guid("11589DD0-43DC-4D67-B1EF-670680472D77")]
public class Main : IEdmAddIn5
{
public void GetAddInInfo(ref EdmAddInInfo poInfo, IEdmVault5 poVault, IEdmCmdMgr5 poCmdMgr)
{
poInfo.mbsAddInName = "Test Addin";
poInfo.mlAddInVersion = 1;
poInfo.mlRequiredVersionMajor = 28;
poCmdMgr.AddHook(EdmCmdType.EdmCmd_CardButton);
}
public void OnCmd(ref EdmCmd poCmd, ref EdmCmdData[] ppoData)
{
switch (poCmd.meCmdType)
{
case EdmCmdType.EdmCmd_CardButton:
string addInTagName = poCmd.mbsComment;
if (addInTagName == "MyTestButton")
{
var enumVar = poCmd.mpoExtra as IEdmEnumeratorVariable5;
object varVal;
enumVar.GetVar("SL_BENENNUNG","@", out varVal);
var retVal = varVal?.ToString();
((EdmVault5)(poCmd.mpoVault)).MsgBox(poCmd.mlParentWnd, "Call from OnCmd: " + retVal);
Form1 form1 = new Form1(ref poCmd);
form1.Show();
}
break;
}
}
}
}
This is my Form1.cs:
using EPDM.Interop.epdm;
using System;
using System.Windows.Forms;
namespace MyTestAddin
{
public partial class Form1 : Form
{
private EdmCmd _poCmd;
public Form1(ref EdmCmd poCmd)
{
InitializeComponent();
var enumVar = poCmd.mpoExtra as IEdmEnumeratorVariable5;
object varVal;
enumVar.GetVar("SL_BENENNUNG", "@", out varVal);
var retVal = varVal?.ToString();
((EdmVault5)(poCmd.mpoVault)).MsgBox(poCmd.mlParentWnd, "Call from Form1 constructor: " + retVal);
_poCmd = poCmd;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
var enumVar = _poCmd.mpoExtra as IEdmEnumeratorVariable5;
object varVal;
enumVar.GetVar("SL_BENENNUNG", "@", out varVal);
var retVal = varVal?.ToString();
((EdmVault5)(_poCmd.mpoVault)).MsgBox(_poCmd.mlParentWnd, "Call from button1_Click: " + retVal);
}
}
}
Now the following happens:
when i press the button in my datacard, a message box opens with the text: Call from OnCmd: Test
The word Test comes from the variable. So this is exactly what I was expacting.
The next thing that happens is a message box opens with the text: Call from Form1 constructor: Test
Again this is exactly what I was expacting.
Now the Form1 is open and I click on the button. The button2_Click Event is raised and I get an error on this line:
enumVar.GetVar("SL_BENENNUNG", "@", out varVal);
The error is: Error HRESULT E_FAIL has been returned from a call to a COM component
Can anyone please explain this to me? What did I do wrong?