C# DirectX input problem - c#

So i have simple application, just a few lines:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX.DirectInput;
namespace asdasd
{
public partial class Form1 : Form
{
public Device joystick;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
foreach (
DeviceInstance di in
Manager.GetDevices(
DeviceClass.GameControl,
EnumDevicesFlags.AttachedOnly))
{
joystick = new Device(di.InstanceGuid);
break;
}
if (joystick == null)
{
throw new Exception("No joystick found.");
}
}
}
}
and i try to get the active joystick on my computer, but i get error:
i have the assembly Microsoft.DirectX.DirectInput and i have directX SDK 2010 installed.
Can someone tell me where is the problem?

Try adding this to the config file:
http://devonenote.com/2010/08/mixed-mode-assembly-error-after-upgrading-to-dotnet-4-0/
(if configuration already exists, just merge these in)
And, maybe it's not the right place, but just take a look at XNA... Things are usually much easier with that.
I couldn't paste the XML directly here, it doesn't show up.

The DirectX assemblies are built against .NET v1.1 Microsoft stopped actively developing them before .NET v2.0 was released.
They cannot be used in projects targeting other than .NET v1.1. XNA is the "blessed" path forward for managed access to Direct X features. I don't know all if it's features, but SlimDX appears to give a more Direct X feeling API for C# than XNA, though I have not used it, I've heard a lot about it.
You might find better responses for chosing an upgrade path over at gamedev.stackexchange.com though.

Related

when i use the directx library, form screen is not come on c# form application

when i use the directx library, form screen is not come on c# form application
i have a code like this,
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;
namespace Creating_A_Basic_DirectX
{
public partial class Form1 : Form
{
private Device device;
public Form1()
{
InitializeComponent();
InitializeDevice();
}
private void InitializeDevice()
{
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
device.Clear(ClearFlags.Target, Color.DarkSlateBlue, 1.0f, 0);
device.Present();
}
}
}
and i was run this code but form screen is not come.
when i was delete directx codes, its run.
i change properties(double click)-->build-->Platform target-->x86
Microsoft.DirectX and Microsoft.DirectX.Direct3D are legacy Managed DirectX 1.1 assemblies. They were created for .NET 1.1 and have been legacy for a very long time. They were last updated in August 2005, are not compatible with .NET 4.x or later, and are only deployed by the legacy DirectSetup package (i.e. they are not included with .NET or any OS).
You should look to use some modern equivalent including SharpDX, SlimDX, or Unity 3D.
See DirectX and .NET

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

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.

C# "await" error when using WinRT from Desktop app

I trying to get my GPS position from a Desktop app, using Windows Runtime, in C#.
I followed this how-to to set up Visual Studio and this code sample to create the following trivial code as a C# console app :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime;
using System.Windows;
using Windows;
using Windows.Devices.Geolocation;
using Windows.Foundation;
using Windows.Foundation.Collections;
namespace GeoLocCS
{
public sealed partial class Program
{
static void Main(string[] args)
{
Test test = new Test();
Console.Read();
}
}
public class Test
{
private Geolocator geolocator;
public Test()
{
Console.WriteLine("test");
geolocator = new Geolocator();
this.getPos();
}
async void getPos()
{
Geoposition pos = await geolocator.GetGeopositionAsync();
Console.WriteLine(pos.Coordinate.Latitude.ToString());
}
}
}
When trying to compile, I get the error :
Error 1 'await' requires that the type 'Windows.Foundation.IAsyncOperation<Windows.Devices.Geolocation.Geoposition>' have a suitable GetAwaiter method. Are you missing a using directive for 'System'?
I tried to reference every DLL that I could, like "System.runtime", "System.Runtime.WindowsRuntime", "Windows.Foundation"...
What I am missing ?
Thanks for the answer,
Serge
I finally figured out my problem :
I am on 8.1 so I changed this in the .csproj file (targetingPlatform) instead of targeting 8.0
After that modification, I could reference "Windows"
I manually referenced the two following DLLs :
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5\Facades\System.Runtime.dll
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Runtime.WindowsRuntime.dll
If you are On Win8.1 Please Use:
<TargetPlatformVersion>8.1</TargetPlatformVersion>
and not 8.0.
Adding to the existing answers:
I suddenly got this problem with a multiproject solution in WPF (still don't know why). I tried switching between TargetPlatformVersions 8.1 and 10.0, tried using the v4.5- and v4.5.1-System.Runtime.WindowsRuntime.dll, always alternating between BadImageFormatException and FileNotFoundException.
Turned out to be references in some of the app.config-files (not the .csproj-files!). Visual Studio 2017 must have added them at some point and as soon as I removed these entries, the above solutions finally worked.

Microsoft.DirectX.AudioVideoPlayback program not working

I'm trying to write a simple program that I'm going to be using inside another program for playing back audio and video files using the Microsoft.DirectX.AudioVideoPlayback.dll file. I've got the code listed below since it doesn't have to be incredibly complex. The problem that I am having is that... well, the program does nothing. Not even the main window shows up and I don't know why. I'm using .Net 4.0 and the DirectX DLL version says it's 1.0.2902.0. I tried moving the initialization for the audio and video files to different places (The load event and the button press event specifically). When in the button press event, the form loads, but as soon as I press a button, the program hangs. No errors or anything. Anyone know what is going on here? If someone has a better idea for playing audio and video files, I'm willing to consider that too.
using Microsoft.DirectX.AudioVideoPlayback;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MediaPlayer
{
public partial class Player : Form
{
Audio derp;
Video herp;
public Player()
{
InitializeComponent();
this.derp = new Audio("<Audio File Name>");
this.herp = new Video("<Video File Name>");
this.herp.Owner = this.panel1;
}
private void btnPlayPauseStop_Click(object sender, EventArgs e){
switch(((Button)sender).Text){
case "Play":
if (!herp.Playing)
herp.Play();
break;
case "Pause":
if (!herp.Paused)
herp.Pause();
break;
case "Stop":
if (!herp.Stopped)
herp.Stop();
break;
}
}
private void Player_Load(object sender, EventArgs e)
{
}
}
}
I have been using this for making my very own "Media Player Classic" clone
Be sure to debug this in 32 bit mode:
Project Menu --> {project} Properties ... --> Build --> Platform Target = x86
For video, I do not load Audio (it gets done automatically). So instead of using both, use only the one needed (video or audio)
The next thing is to ensure that the panel is visible and big enough to see (check the size after "new Video(...)")

I dont understand how to use the open hardware monitor source code

I added to the reference the OpenHardwareMonitorLib.dll
Now I added in my code: using OpenHardwareMonitor.Hardware;.
Then I did in the top form level: Isensor Sensor;
But I can't "new" it i cant create an instance of it and I'm getting null exception on it in the constructor:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using OpenHardwareMonitor.Hardware;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
ISensor Sensor;
public Form1()
{
InitializeComponent();
string t = Sensor.Name;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}
Cannot create an instance of the abstract class or interface 'OpenHardwareMonitor.Hardware
I tried ot look in the source code in the code.google.com site: http://code.google.com/p/open-hardware-monitor/source/browse/#svn%2Ftags%2F0.3.2%2FWMI
But i dont want to use all this code. I downloaded the program Open Hardware Monitor and except the exe file there is a dll file im using now in my project i was sure i can use the dll to use it easier. All i want for now is to get the temperature of the video card gpu.
First, you can't new interfaces. You can only new concrete classes.
Second, I recommend renaming your variable from Sensor to sensor, or _sensor, or something along these lines. There is a Sensor class. It's best to avoid confusion.
What I did was downloaded the DLL and opened it up in ILSpy. Let's see what classes implement this interface. I urge you to download ILSpy and try this out for yourself.
Here's the resulting ILSpy window. Now in the bottom right I had done an "Analyze" on the interface to see where it is exposed. There don't appear to be any factory methods that return an ISensor.
Back over on the left side, we see that one class implements ISensor: the Sensor class. This class has four constructors. These will come up in intellisense in Visual Studio, or if you navigate to the Sensor class in ILSpy you can see the constructors.
What you'll end up needing to do is sensor = new Sensor(...); As for which constructor you use... that's up to you.

Categories