I've been trying to convert this WinRT interface from its C++ Origin Code, to C# based code:
IDL File:
namespace Windows.Internal.Security.Authentication.Web{
[version(1)]
[uuid(07650a66-66ea-489d-aa90-0dabc75f3567)]
interface ITokenBrokerInternalStatics : IInspectable {
HRESULT filler_GetTokenSilently();
HRESULT filler_GetSecureInputParameters();
HRESULT filler_ReportBackgroundCompletion();
HRESULT filler_FindAccount();
HRESULT filler_FindAccountForApp();
HRESULT filler_FindAccountForProvider();
HRESULT FindAllAccountsAsync(
[out][retval] Windows.Foundation.IAsyncOperation<Windows.Foundation.Collections.IVectorView<Windows.Security.Credentials.WebAccount > *> ** operation);
}
[version(1)]
[static(Windows.Internal.Security.Authentication.Web.ITokenBrokerInternalStatics, 1)]
[marshaling_behavior(agile)]
[threading(both)]
runtimeclass TokenBrokerInternal {
}
}
CPP File:
auto tokenBrokerStatics = get_activation_factory<TokenBrokerInternal, Windows::Foundation::IUnknown>();
auto statics = tokenBrokerStatics.as<ITokenBrokerInternalStatics>();
auto accounts = statics.FindAllAccountsAsync().get();
This is what I got so far:
using PInvoke;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Text;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Foundation.Metadata;
using Windows.Internal.Security.Authentication.Web;
using Windows.Security.Credentials;
using GuidAttribute = System.Runtime.InteropServices.GuidAttribute;
namespace Windows.Internal.Security.Authentication.Web
{
[Version(1)]
[Guid("07650a66-66ea-489d-aa90-0dabc75f3567")]
[InterfaceType(ComInterfaceType.InterfaceIsIInspectable)]
public interface ITokenBrokerInternalStatics
{
Windows.Foundation.IAsyncOperation<IReadOnlyList<Windows.Security.Credentials.WebAccount>> FindAllAccountsAsync();
}
[Version(1)]
[MarshalingBehavior(MarshalingType.Agile)]
[Threading(ThreadingModel.Both)]
[Static(typeof(Windows.Internal.Security.Authentication.Web.ITokenBrokerInternalStatics), 1)]
public class TokenBrokerInternal { }
public static class TokenBrokerInternalAssist
{
public static ITokenBrokerInternalStatics GetTokenBrokerInternal()
{
var tokenBrokerStatics = WindowsRuntimeMarshal.GetActivationFactory(typeof(TokenBrokerInternal));
var statics = (ITokenBrokerInternalStatics)tokenBrokerStatics.ActivateInstance()
return statics;
}
}
}
However, I can't seem to get it to work despite my best efforts. Here's a couple of errors I've encountered while trying to get this working:
Casting Errors
Activation Factories Not Existing
Many Other Errors related to dumb mistakes
I'm pretty new at this WinRT stuff, but despite looking on multiple sites for answers to my problem, I've found myself at a dead-end, and I really just wanna convert this code to C# to avoid having to compile a C++ project twice to support Any CPU and the complicated compiling of my app. What am I doing wrong?
P.S. This is not a UWP app, so don't suggest WebAccountManager or anything UWP specific, please.
Related
Trying to remotly connect to another PC's WMI but when creating the CimSession I get the following error
System.InvalidProgramException:'Common Launguage Runtime detexted an invalid program'
The code I am running is as follows
using System;
using System.Text;
using System.Threading;
using Microsoft.Management.Infrastructure;
using Microsoft.Management.Infrastructure.Options;
using System.Security;
namespace SMAPIQuery
{
class Program
{
static void Main()
{
string computer = "ComputerB";
DComSessionOptions DComOptions = new DComSessionOptions();
DComOptions.Impersonation = ImpersonationType.Impersonate;
CimSession Session = CimSession.Create(computer, DComOptions);
}
}
}
Unsure as to what throws this error or how to get around it
The issue was I was using .Net Core and not .Net Framework
I have written a code in c++ and c# . From my c++ code i am calling my c# function through. I have sent just a part of c++ code.
txtPath contains the location of a text file.
C++ code:
CoInitialize(NULL);
IMyClassPtr obj3;
obj3.CreateInstance(__uuidof(Program));
obj3->Validation(txtPath);
CoUninitialize();
Validation() is my c# function.
My c# code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
using word = Microsoft.Office.Interop.Word;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace ABC
{
[ComVisible(true)]
public interface IMyClass
{
void Validation(string txtp);
}
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
public class Program : IMyClass
{
private string replace_string(string text)
{
return text.Replace("\r\a", "");
}
public void Validation(string txtp)
{
string[] textValidate = File.ReadAllLines(txtp);
string textpath = txtp;
//validation starts here
foreach (string line in textValidate)
{
string[] strsplit = line.Split(new string[] { "," }, StringSplitOptions.None);
string task = strsplit[0];
string sign = strsplit[1];
string person = strsplit[2];
string routing = strsplit[3];
if (String.IsNullOrEmpty(task) || String.IsNullOrEmpty(sign) || String.IsNullOrEmpty(person))
{
//if the txt file is invalid
MessageBox.Show("Signature.txt is incomplete or has invalid input!!!");
}
}
}
}
}
I have done all the required setting in c# .C# settings snapshot C# project is a class library. My code was working perfectly in 32 bit machine. I was using the generated tlb in other systems by registering it with regasm.exe.
In 64 bit machine by c++ code is working but when the c# linking code is hit the execution stops without throwing any error. I am using a 64 bit machine and created a new project with the same code. Help Please
Make you're using the correct version of 'regasm.exe' for your target platform (i.e. "C:\Windows\Microsoft.NET\Framework64\v2.0.50727\RegAsm.exe"). Take note of 'Framework64'.
On 64-bit Windows, Microsoft does not support loading a 64-bit DLL into a 32-bit process, or vice-versa. For additional information, please refer to the following resource on MSDN:
http://msdn.microsoft.com/en-us/library/aa384231(VS.85).aspx
I'm trying to play OGG file stream with NVorbis and NAudio, as described in the documention i'm trying to access VorbisWaveReader class, without success, here is my code:
using System;
using System.Collections.Generic;
using System.Text;
using NVorbis;
using NAudio;
namespace Paradise
{
class Program
{
static void Main(string[] args)
{
using (var vorbis = new NVorbis.NAudioSupport.VorbisWaveReader(#"C:\PATH\TO\OGG\FILE.ogg"))
using (var waveOut = new NAudio.Wave.WaveOut())
{
waveOut.Init(vorbis);
waveOut.Play();
}
}
}
}
I'm getting the following error:
type or namespace name 'VorbisWaveReader' does not exist in the namespace 'NVorbis.NAudioSupport'
It looks very basic and should work, i can see in the source code that VorbisWaveReader is present in the code, can you help me go thorugh that?
Thanks!
NVorbis.NAudioSupport change into NAudio.Vorbis
in Package-Manager Console type this:
Install-Package NAudio.Vorbis
I want to run the Skeinforge slicer program written in Python inside my Windows Phone 8 C# application. I have determined that I should probably use IronPython to do this, I have already determined that I can run Skeinforge inside the ipy.exe terminal I got when I installed IronPython. My problem though is that I am struggling to figure out how to host and run a Python script with IronPython inside Windows Phone 8. I have also already managed to get a simple hello world script running inside a Desktop Windows Forms application that transfers the applications console output to the Debug console with the following code:
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.Diagnostics;
using System.IO;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
DebugWriter debugW = new DebugWriter();
Console.SetOut(debugW);
}
private void button1_Click(object sender, EventArgs e)
{
TextWriter tw = new StreamWriter("Test.py");
tw.Write(scriptBox.Text);
tw.Close();
try
{
var ipy = Python.CreateRuntime();
dynamic test = ipy.UseFile("Test.py");
}
catch (Exception ex)
{
Debug.WriteLine("Error: " + ex.Message);
}
}
}
}
And this is the DebugWriter:
class DebugWriter : TextWriter
{
private StringBuilder content = new StringBuilder();
public DebugWriter()
{
Debug.WriteLine("Writing console to debug");
}
public override void Write(char value)
{
base.Write(value);
if (value == '\n')
{
Debug.WriteLine(content.ToString());
content = new StringBuilder();
}
else
{
content.Append(value);
}
}
public override Encoding Encoding
{
get { return System.Text.Encoding.UTF8; }
}
}
I have no idea how to even add the IronPython libraries to my Windows Phone 8 application though as the standard libraries won't import. I have though tried compiling the apparently now defunct Windows Phone 7 libraries with the master source code and I can import these libraries, but I get absolutely no response on the debug terminal when I try to run my hello world script.
Do any of you have any idea how to get this woring in Windows Phone 8, if you know how to do this in Windows 8/Metro/RT then that would also probably work for WP8.
UPDATE:
I have looked at the debug output again and I seem to get this error when trying to use the WP7 libraries to run a hello world script:
A first chance exception of type 'System.NotImplementedException' occurred in Microsoft.Scripting.DLL
Error: The method or operation is not implemented.
I managed to get Skeinforge running on a modified version of IPY. You can get the source for my application here: http://skeinforgewp8.codeplex.com/
I added as reference 3 dll's: Google.Apis , Google.Apis.Translate.v2 , System.Runtime.Serialization
In Form1 i have one line:
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Translator.translate(new TranslateInput());
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
Now the error the exception is on the first line in the class Translator:
The line that throw the error is: var service = new TranslateService { Key = GetApiKey() };
The class code is:
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 System.Net;
using System.IO;
using System.Web;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using Google.Apis.Util;
using Google.Apis.Translate.v2;
using Google.Apis.Translate.v2.Data;
using TranslationsResource = Google.Apis.Translate.v2.Data.TranslationsResource;
public class Translator
{
public static string translate(TranslateInput input)
{
// Create the service.
var service = new TranslateService { Key = GetApiKey() };
string translationResult = "";
// Execute the first translation request.
Console.WriteLine("Translating to '" + input.TargetLanguage + "' ...");
TranslationsListResponse response = service.Translations.List(input.SourceText, input.TargetLanguage).Fetch();
var translations = new List<string>();
foreach (TranslationsResource translation in response.Translations)
{
translationResult = translation.TranslatedText;
}
return translationResult;
}
private static string GetApiKey()
{
return "AIzaSyCjxMe6RKHZzd7xSfSh2pEsBqUdXYm5tA8"; // Enter Your Key
}
}
/// <summary>
/// User input for this example.
/// </summary>
[Description("input")]
public class TranslateInput
{
[Description("text to translate")]
public string SourceText = "Who ate my candy?";
[Description("target language")]
public string TargetLanguage = "fr";
}
The error is:
Could not load type 'Google.Apis.Discovery.FactoryParameterV1_0' from assembly 'Google.Apis, Version=1.1.4497.35846, Culture=neutral, PublicKeyToken=null'.
Tried to google for help and also tried to change the project type to x64 platform but it didnt help. So i put it back on x86
I have windows 7 64bit visual studio c# 2010 pro .net 4.0 profile client.
Cant figure out what is the error ?
This error as reported in the above-posted messages is due to a local copy in the bin\Debug folder of your solution or project. Even though you attempt to clean your solution, such copies will persist to exist.
In order to avoid this to happen, you have to force Visual Studio to refer to the correct DLL by adding reference paths within a project properties. Unfortunately, if you got several projects within your solutions, you will have to set the reference paths for the projects one after another until completed.
Should you wish to know how to setup reference paths follow these simple instructions:
1.Select your project, right-click, then click "Properties";
2.In the project properties, click "Reference Paths";
3.Folder, type or browse to the right location of your DLL, click [Add Folder].
You will need to perform these steps for as many different locations you may have for each of your DLLs. Consider setting an output path under the Build tab of the same project properties, so that you may output your DLLs in the same directory for each of them, thus assuring you to find all the latest builds under the same location, simplifying forward your referencing.
Note this can only be one reason for this error. But it is sure that is has to do something with a wrong copy of the mentioned assembly.