I cant get SevenZipLib library to work (p/invoke) - c#

Very basic knowledge on c# and is the first i use anything p/invoke related.
Help me pls, i have made this code but it doesnt seem to work.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
[DllImport("C:\\Users\\lchris\\Desktop\\SevenZipLib_9.13.2\\SevenZipLib\\SevenZipLib\\7z86.dll")]
public static extern void SevenZipArchive(string c);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
using (SevenZipArchive archive = new SevenZipArchive("file.rar"))
{
foreach (ArchiveEntry entry in archive)
{
Console.WriteLine(entry.FileName);
}
}
}
}
}
It tells me that SevenZipArchive is a 'Method' and is being used like a 'type'.
I have include the library to my project already, i just dont know how to use it.
Here is the library:
https://sevenziplib.codeplex.com/

You first need to remove this code:
[DllImport("...")]
public static extern void SevenZipArchive(string c);
You do not need to provide any p/invoke declarations. The library wraps that up for you.
This is a .net assembly. You use it just as you use any other. Take the following steps:
Download the project. You already did that I think.
Build the solution. Make sure that
In your project, add a reference to the assembly that you built in the previous stage. It's SevenZipLib\bin\Debug\SevenZipLib.dll or SevenZipLib\bin\Release\SevenZipLib.dll depending on the target you selected.
Add using SevenZipLib; to your project code to to gain access to the namespace.
Once you've done that your code will work. You can use the tests project that is supplied as part of the download as a rich source of example code.

Related

Integrate C++ .dll wrapped by SWIG to C# project

I have 2 solutions under VS2019: RLibrary (contains C++ project) and VTApp (contains C# project).
Solution RLibrary has two projects: RLib C++ .dll and SwigW (wrapper project).
SwigW generated the following files: RLibCSHARP_wrap.cxx, RLib.cs, RLib.i and RLibPINVOKE.cs.
In the RLibPINVOKE.cs I have lines like:
class RLibPINVOKE {
//...
static RLibPINVOKE() {
}
[global::System.Runtime.InteropServices.DllImport("SwigW", EntryPoint="CSharp_new_Create")]
public static extern global::System.IntPtr new_Create();
[global::System.Runtime.InteropServices.DllImport("SwigW", EntryPoint="CSharp_new_Request")]
public static extern global::System.IntPtr new_Request();
// ...
}
So, after building RLibrary solution I will have two .dll (also .lib) files: RLib.dll and SwigW.dll.
I want to use new_Create(), new_Request() functions from the VTApp.
VTApp has two projects as well: UI and Core. UI has a reference to Core. I added RLibPINVOKE.cs file to the Core project by just Right Click->Add->Existing item and tried to use above mentioned functions from the UI project within namespace UI, i.e.,
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Input;
using Core;
using Newtonsoft.Json;
namespace UI {
public partial class MainWindow {
private void Execute_Req(object sender, EREventArgs e)
{
//...
IntPtr p = new_Create();
}
}
}
Unfortunately, I am getting CS01013: The name 'new_Create' does not exist in the current context. error.
In my opinion, even without adding SwigW.dll to the Core project I shouldn't have had this kind of compile time error. So, what is the problem here? How can I add SwigW.dll into the Core project properly if I need to add it? Also, should I add RLib.dll to the Core as well?
Try RLibPINVOKE.new_Create(). The method is inside a class RLibPINVOKE
class RLibPINVOKE {
//...
You'll perhaps need a using, but the Visual Studio should be able to suggest it to you on the RLibPINVOKE.

I have a solution with two projects how can i use methods from the library type project in the winforms project?

The first project is Class Library.
I can't just run it so i added a winforms project so i can use the Library methods and classes so i can debug the Library project.
But i can't get to the Lubrary project form the winforms.
In the winforms:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
}
}
}
And the Library project name is AviFile and inside it there are classes.
When i type in the timer tick event AviFile it's not exist.
You need to add reference to your class library project named AviFile in your winform project by right clicking Reference -> Add reference -> Select Project -> choose the dll and select OK.
Then in your Form class import the namespace saying using AviFile;
See MSDN Documentation on how to do that.

Creating Device in C# (Device not recognized as keyword)

I decided to try working with C# over c++ but ran into a problem.
The following code snippet shows the problem.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using System.Device;
namespace Project_AREA
{
public partial class Form1 : Form
{
private Device device;
public Form1()
{
InitializeComponent();
}
}
}
That's as much code as I have right now.
In private Device device;, the keyword Device is not getting recognized although all the libraries have been referenced and the using directives are included.
Any ideas?
Managed to Solve the problem.. for your reference and also if other run in to the same problem. You must add all the following references to the project: (note all files can be found on your had disk at c:\Windows\Microsoft.NET\DirectX for Managed Code) 1: Microsoft.DirectX.dll from folder 1.0.2902.0 2: Microsoft.DirectX.Direct3D.dll from folder 1.0.2902.0 3: MicrosoftMicrosoft.DirectX.Direct3DX.dll from folder 1.0.2911.0 Thanks for the help tho guys :)

Missing Using directive for hierarchical_grouping in MSDN crystal reports tutorial

I was working through the MSDN tutorial for Crystal Reports, and I get to the Binding the Embedded Report to the CrystalReportViewer Control step:
When I try the build, it tells me that I am missing my using declaration for Hierarchical_Grouping class. This brings up two questions for me...
What is the namespace for this class definition?
Is there an easy way of determining the namespace of a given class?
In another answer I saw the 'ALT, SHIFT, F10' and the 'CTRL, [period]' suggestions for intellisense, but they don't work in my Visual Studio.
I'm sure I have done something ridiculously stupid....sorry in advance....
Here's the code for the form:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
namespace CrystalTest3
{
public partial class Form1 : Form
{
private Hierarchical_Grouping hierarchicalGroupingReport;
public Form1()
{
InitializeComponent();
}
private void ConfigureCrystalReports()
{
hierarchicalGroupingReport = new Hierarchical_Grouping();
crystalReportViewer.ReportSource = hierarchicalGroupingReport;
}
private void Form1_Load(object sender, EventArgs e)
{
ConfigureCrystalReports();
}
}
}
I am assuming that you are referring to this tutorial.
The Hierarchical_Grouping seems to refer to the report file - which will contain the class named Hierarchical_Grouping. Have you added the report to your project?
The report should be somewhere in these Sample Reports Directories.

cannot create instance of supersocketserver AppServer

I am trying to get the SuperSocketServer app up an running. However, I cannot seem to create an instance of the server. Here is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SuperSocket.SocketBase;
using SuperSocket.SocketBase.Config;
using SuperSocket.SocketEngine;
using SuperSocket.SocketBase.Protocol;
namespace WinnieServer
{
class Program
{
AppServer W = new AppServer();
static void Main(string[] args)
{
Console.Write("Starting...");
while (true)
{
}
}
}
}
I tried the examples in the source code. However, they all give the same error:
Cannot create an instance of the abstract class or interface 'SuperSocket.SocketBase.AppServer'
Is this the correct way to create an instance of SSS?
take care,
lee
I had this same issue. The download on their home screen gives you the 1.4.4 version. If you look in object explorer it IS abstract. If you go to their downloads and grab the binaries zip, you'll get the 1.5 version that ISN'T abstract.

Categories