在C#代码上效果很好。但是,如果我使用c#dll在c ++上执行,则会发生异常处理错误。
首先,我给你看我的代码。
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();
}
}
}
}
#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;
}
调试C ++代码时,在此处生成错误
LoginClassPtr pICalc(__uuidof(Class1));
如果接收dll函数的过程出错,我试图将C#的函数部分更改为非常简单的函数,该函数可以计算两个整数的和,并且可以正常工作而不会出现错误。
[仅此一个问题使我无法前进两天。我需要您的帮助。
我正在研究类似的问题,我的c#dll是用强名称签名的dll。我使用的Selenium Webdriver nuget软件包的名称不强。显然,强名称的dll无法加载没有强名称的另一个dll。我卸载了selenium webdriver软件包并安装了selenium webdriver.strongname,这对我有用。