It works well on the c# code. However, an exception handling error occurs if i execute at c++ with c# dll.
First, I'll show you my code.
- C# code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace ManagedLibrary1
{
public interface LoginClass
{
void LogIn(string id, string pw, int t, int num);
void LogOut();
}
public class Class1 : LoginClass
{
IWebDriver driver = new ChromeDriver();
IWebElement a;
Boolean b;
public void LogIn(string id, string pw, int t, int num)
{
if (num == 0)
{
driver.Navigate().GoToUrl("this is url address");
}
else
{
driver.Url = "this is url address2";
}
Thread.Sleep(50);
if (t == 0)
{
a = driver.FindElement(By.XPath("this is Xpath"));
b = a.Displayed;
if (b == true)
{
a.Click();
}
}
driver.FindElement(By.XPath("this is xpath2")).SendKeys(id);
Thread.Sleep(50);
driver.FindElement(By.XPath("this is xpath3"]")).SendKeys(pw);
Thread.Sleep(50);
driver.FindElement(By.XPath("this is xpath4")).Click();
Thread.Sleep(5000);
a = driver.FindElement(By.XPath("this is xpath5"));
if (b == true)
{
driver.Url = "this is url address 3";
}
driver.Manage().Window.Maximize();
driver.FindElement(By.ClassName("this is classname")).Click();
}
public void LogOut()
{
a = driver.FindElement(By.XPath("this is xpath6"));
b = a.Displayed;
if (b == true)
{
a.Click();
}
}
}
}
- C++ code
#include <windows.h>
#include "tchar.h"
#import "C:\Users\me\Desktop\Project Folder\ClassLibrary4\ClassLibrary4\bin\Debug\ClassLibrary4.tlb" raw_interface_only
using namespace ClassLibrary4;
int main()
{
HRESULT hr = CoInitialize(NULL);
LoginClassPtr pICalc(__uuidof(Class1));
pICalc->LogIn("id","password",1,0);
CoUninitialize();
return 0;
}
when debugging C++ code, error generate here
LoginClassPtr pICalc(__uuidof(Class1));
If the process of receiving the function of dll was wrong, I tried to change the function part of C# into very simple function that calculates the sum of two integers, and it worked well without errors.
Only this one problem has kept me from going forward for two days. I want your help.