axShockwaveFlash_FSCommand not responding on some machines - c#

I have created a C sharp project in which i have added a ShockwaveFlashObject to play my swf file.
The problem i am facing is when i create an installer for my project it works correctly on my machine on installation, but on my laptop the swf loads correctly but doesn't respond to the _FSCommand. I cannot use a try and catch block as it is not entering the FSCommand handle. Do i need to bundle something with my installation?
The laptop i am using is brand new and i wanted it that way so that i know what all stuff is needed for things to work correctly so that i can add prerequisites to my installer.
Also idk if this information is of any use but I am using advanced installer to build and exe for my project.
PS i have added things like the below code to know if FSCommand gets executed.
MessageBox.Show("step 1/2/3");
Here is the entire code.
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 MySql.Data.MySqlClient;
using System.IO;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Globalization;
namespace WindowsFormsApplication1
{
public partial class frmFlashIntro : Form
{
public Form FormfrmMainRef { get; set; }
public frmFlashIntro()
{
InitializeComponent();
axShockwaveFlash1.Playing = true;
FormBorderStyle = FormBorderStyle.None;
WindowState = FormWindowState.Maximized;
string currentPath = Directory.GetCurrentDirectory();
axShockwaveFlash1.Movie = "file://\\" + currentPath + "\\intro.swf";
}
private void axShockwaveFlash1_FSCommand(object sender, AxShockwaveFlashObjects._IShockwaveFlashEvents_FSCommandEvent e)
{
MessageBox.Show("step 1");
string btn = e.command.ToString();
MessageBox.Show("step 2");
if (btn == "play")
{
MessageBox.Show("step 3");
try
{
MessageBox.Show("step 4");
var form2 = new frmMain();
MessageBox.Show("step 5");
this.Hide();
MessageBox.Show("step 6");
form2.Show();
}
catch (Exception ex) { MessageBox.Show(ex.ToString()); }
}
if (btn == "syllabus")
{
MySqlConnection con = new MySqlConnection(Properties.Settings.Default.conString);
con.Open();
Syllabus_usageInformation syl = new Syllabus_usageInformation(this);
MySqlCommand cmd = new MySqlCommand("SELECT ImageFiles FROM misc WHERE id=1", con);
byte[] img = (byte[])cmd.ExecuteScalar();
string strFn = Convert.ToString(DateTime.Now.ToFileTime());
FileStream fs = new FileStream(strFn, FileMode.CreateNew, FileAccess.Write);
fs.Write(img, 0, img.Length);
fs.Flush();
fs.Close();
con.Close();
syl.kpImageViewer1.OpenButton = false;
syl.kpImageViewer1.ImagePath = strFn;
syl.Show();
this.Hide();
}
if (btn == "usageInformation")
{ }
}
}
}

Is flash player ActiveX control installed on your laptop? You have to install it, otherwise there's nothing that can play your .swf file.

Related

Access to file denied in C# .NET 3.1 forms

Hello I was writing a basic text editor in C# on visual studio windows form using the .NET framework 3.1 long term support version everything worked fine until I wrote the save file script
Here's the code for "Form1.cs" which is where the open and save file functions reside
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.IO;
using System.Security.Principal;
namespace Text_Editor
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string locsave;
private void openbtn_Click(object sender, EventArgs e)
{
var identity = WindowsIdentity.GetCurrent();
var principal = new WindowsPrincipal(identity);
if (principal.IsInRole(WindowsBuiltInRole.Administrator) != true)
{
MessageBox.Show("Run as Admin");
System.Windows.Forms.Application.ExitThread();
}
else
{
OpenFileDialog openfile = new OpenFileDialog();
if (openfile.ShowDialog() == DialogResult.OK)
{
var locationArray = openfile.FileName;
string location = "";
locsave = locationArray;
foreach (char peice in locationArray)
{
location = location + peice;
}
var contentArray = File.ReadAllText(location);
string content = "";
label4.Text = location;
foreach (char peice in contentArray)
{
content = content + peice;
}
richTextBox1.Text = content;
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
Console.WriteLine("Test");
}
private void savebtn_Click(object sender, EventArgs e)
{
if (#label4.Text == "")
{
MessageBox.Show("Open a text file first");
}
else
{
StreamWriter outputfile = new StreamWriter(locsave);
outputfile.Write(richTextBox1.Text); //this is where the error occures and it throws the error of access denyed
outputfile.Close();
}
}
}
}
Does anyone have a suggestion about what to do I looked around on google for a solution but it seemed most did not work and some others I did not understand.

keep having this exception System.Data.OleDb.OleDbException (0x80004005):?

i am developping a really simple program in c# with Visual studio, it consists simply by extracting data from an Excel sheet and transfer it to a database (only one table ), using MySql it worked i just saved the files as CSV and then imported them into my database but i had a big problem which was the encoding UTF8 i have many french characters ans arabic ones that just showed as random characters, so i went back to OleDb but it keeps shong exceptions now i am stuck with this one: System.Data.OleDb.OleDbException (0x80004005)
i ve tried to change running config to x86 but nothing (notice that i am using a windows 8 X64). its a cummon ISAM problem.
please help me .
this is my 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 Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
using System.IO;
using System.Data.OleDb;
namespace testoledb
{
public partial class Form1 : Form
{
DataSet OleDs = new DataSet();
OleDbDataAdapter OleAdapter = new OleDbDataAdapter();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
}
private void upload_excl_Click(object sender, EventArgs e)
{
string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
path = Path.Combine(path, "AGENDA.xlsx");
string OleConnectionString = #"Provider=Microsoft.ACE.OLEDB.12.0;Data Source="+path+#";Extend Properties=Excel 12.0 Macro;MDR=Yes;ImportMixedTypes=Text;TypeGuessRows=0"; //,HDR=Yes;IMEX=1""";
OleDbConnection OleConn = new OleDbConnection(OleConnectionString);
string OleStrCmd = "select * from [SHeet1$A1:H330]";
OleDbCommand OleCmd = new OleDbCommand(OleStrCmd, OleConn);
try
{
OleConn.Open();
OleDs.Clear();
OleAdapter.SelectCommand = OleCmd;
OleAdapter.Fill(OleDs);
dataGridView1.DataSource = OleDs.Tables[0];
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
OleConn.Close();
}
}
}
}

MessageBox not showing (focused) after SaveFileDialog

For some reason after my SaveFileDialog, my app will never show the MessageBox. Is there something I'm missing? Or is this a threading issue?
I run the application as a Windows Form application using VS 2010 Express.
I do not get any exceptions.
To add: When I step through the code, all seems to go well. Which is weird, so I believe it is a timing issue.
Pointed out by LarsTech and others, the MessageBoxes do show up, however the focus is gone; in other words the MessageBox is pushed behind other windows or minimized. This is a problem.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using System.IO;
namespace SpeedDating
{
class Program
{
[STAThread]
static void Main(string[] args)
{
string filename = "test.test"; // args[0];
string ext = filename.Substring(filename.LastIndexOf('.'));
SaveFileDialog dialog = new SaveFileDialog();
dialog.Title = "SpeedDating App";
dialog.RestoreDirectory = true;
dialog.CheckFileExists = false;
dialog.CheckPathExists = false;
dialog.FileName = DateTime.Now.ToString("yyyyMMdd") + ext;
DialogResult result = dialog.ShowDialog();
if (result == DialogResult.OK && dialog.FileName != "")
{
try
{
FileStream outfs = File.Create(dialog.FileName);
FileStream infs = File.Open(filename, FileMode.Open);
infs.CopyTo(outfs);
infs.Close();
outfs.Close();
}
catch (NotSupportedException ex)
{
MessageBox.Show("Probably removed the original file.");
}
}
else
{
MessageBox.Show("No path found to write to.");
}
MessageBox.Show("I came here and all I got was this louzy printline");
}
}
}
I tried this one and it showed right away:
MessageBox.Show(new Form() { WindowState = FormWindowState.Maximized, TopMost = true }, "You clicked Cancel button", "Cancel");
Try this for your Message Box.
MessageBox.Show(this,"Probably removed the original file.");
I created a new project and pasted your code and it works for me. Make sure you have done a full rebuild before running. Also, with this line:
dialog.FileName = DateTime.Now.ToString(format) + "." + ext;
The dialog box will have a file name to begin with. Therefore, only hitting the cancel button (assuming you don't clear the save dialog first) will trigger the message box. Either way, I got the message box to pop up by failing your IF test either way. Your code looks alright.
Perhaps you should put the SaveFileDialog in a using to ensure its disposal prior to the MessageBox call:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using System.IO;
namespace SpeedDating
{
class Program
{
[STAThread]
static void Main(string[] args)
{
string filename = "test.test"; // args[0];
string ext = filename.Substring(filename.LastIndexOf('.'));
using (SaveFileDialog dialog = new SaveFileDialog())
{
dialog.Title = "SpeedDating App by K.Toet";
dialog.RestoreDirectory = true;
dialog.CheckFileExists = false;
dialog.CheckPathExists = false;
dialog.FileName = DateTime.Now.ToString("yyyyMMdd") + ext;
DialogResult result = dialog.ShowDialog();
if (result == DialogResult.OK && dialog.FileName != "")
{
try
{
FileStream outfs = File.Create(dialog.FileName);
FileStream infs = File.Open(filename, FileMode.Open);
infs.CopyTo(outfs);
infs.Close();
outfs.Close();
}
catch (NotSupportedException ex)
{
MessageBox.Show("Probably removed the original file.");
}
}
else
{
MessageBox.Show("No path found to write to.");
}
}
MessageBox.Show("I came here and all I got was this louzy printline");
}
}
}

Invoke a service after windows forms loading

I have an mobile application (.NET CF2 for Windows Mobile 6.1) that starts right after the system startup.
I want to force the form to load and them call a web service. there`s also a button that invokes the WS mannually.
I haven`t managed to first load the form so far. First it invokes the service and them it shows the form up.
Can you help me?
Bellow the code I`m using.
//MAIN FORM OF THE APP
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
namespace AtualizaColetores
{
public partial class frmInicio : Form
{
public frmInicio()
{
InitializeComponent();
Program.ShowHide.ShowTopStatusbar(false);
ThreadPool.QueueUserWorkItem(delegate
{
Thread.Sleep(1000);
//incia animação para indicar processamento em segundo plano
Cursor.Current = Cursors.WaitCursor;
Cursor.Show();
Atualizador executar = new Atualizador();
executar.AtualizaColetor();
});
try
{
Process firstProc = new Process();
firstProc.StartInfo.FileName = #"\WOPT\RF_WOPT.exe";
firstProc.EnableRaisingEvents = true;
firstProc.Start();
firstProc.WaitForExit();
this.Activate();
Form destino = new frmControles();
destino.Show();
}
catch (Exception ex)
{
MessageBox.Show("Erro na incialização do programa: " + ex.Message);
return;
}
//Para a animação para indicar processamento em segundo plano
Cursor.Current = Cursors.Default;
Cursor.Show();
}
}
}
//Center code hereODE TO DOWNLOAD AND REPLACE THE CURRENT VERSION OF THE APP, IF NEEDED
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;
using Ionic.Zip;
namespace AtualizaColetores
{
class Atualizador
{
public void AtualizaColetor()
{
if (File.Exists(#"\WOPT\About.xml"))
{
string versaoAplicativo = "", LocalAplicativo = "", tipoColetor = "";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(#"\WOPT\About.xml");
XmlNodeList xnList = xmlDoc.GetElementsByTagName("VersaoRF");
foreach (XmlNode xn in xnList)
{
versaoAplicativo = xn["versaoAplicativo"].InnerText;
LocalAplicativo = xn["localAplicativo"].InnerText;
tipoColetor = xn["tipoColetor"].InnerText;
}
ConectorWOPT.WOPT executar = new ConectorWOPT.WOPT();
//inserir tratamento de erro aqui.
byte[] arquivo = executar.AtualizaColetores(LocalAplicativo, versaoAplicativo, tipoColetor);
string caminhoWOPT = #"\WOPT";
if (arquivo.Length > 0)
{
try
{
MemoryStream ms = new MemoryStream(arquivo);
FileStream fs = new FileStream(
#"\novaVersao.zip", FileMode.Create);
ms.WriteTo(fs);
ms.Close();
fs.Close();
fs = null;
ms = null;
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
if (System.IO.Directory.Exists(caminhoWOPT))
{
try
{
System.IO.Directory.Delete(caminhoWOPT, true);
if (!System.IO.File.Exists(caminhoWOPT))
{
System.IO.Directory.CreateDirectory(caminhoWOPT);
}
}
catch (IOException e)
{
System.Windows.Forms.MessageBox.Show(e.Message);
}
}
if (File.Exists(#"\novaVersao.zip"))
{
using (ZipFile zip = ZipFile.Read(#"\novaVersao.zip"))
{
foreach (ZipEntry e in zip)
{
e.Extract(#"\WOPT\", ExtractExistingFileAction.OverwriteSilently); // overwrite == true
}
}
System.IO.File.Delete(#"\novaVersao.zip");
System.Windows.Forms.MessageBox.Show("Coletor atualizado com sucesso");
}
else
{
System.Windows.Forms.MessageBox.Show("Falha na atualização");
}
}
}
else
{
System.Windows.Forms.MessageBox.Show("O aplicativo não está instalado neste coletor. Contate um supervisor.");
}
}
}
}
Just delay the processing with a timer or thread. Something along these lines:
public frmInicio()
{
InitializeComponent();
Program.ShowHide.ShowTopStatusbar(false);
ThreadPool.QueueUserWorkItem(delegate
{
Thread.Sleep(1000); // or however long you need
btnZip_Click(this, EventArgs.Empty);
});
}
Or put the call in OnActivate, checking for a first run.
EDIT 1
You have a lot (too much IMO) going on in your constructors. I'm betting the Form visibility issue has a lot to do with the fact that you are creating a Process in your Form constructor and then waiting for that process to complete before continuing. If that app is waiting on the output of your web service call, the thread creation was pointless because you've still made the constructor serially dependent on the call.

Compress Audio upon writing to file

I am trying to create a recorder from audio coming out from soundcard and this is my progress so far, the problem is the recorded audio when saving to file is so large like a song can reach up to hundreds of megabyte.
here's my code
using NAudio.CoreAudioApi;
using NAudio.Wave;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Record_From_Soundcard
{
public partial class frmMain : Form
{
private WaveFileWriter writer;
private WasapiLoopbackCapture waveInSel;
public frmMain()
{
InitializeComponent();
}
private void frmMain_Load(object sender, EventArgs e)
{
MMDeviceEnumerator deviceEnum = new MMDeviceEnumerator();
MMDeviceCollection deviceCol = deviceEnum.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active);
cboAudioDrivers.DataSource = deviceCol.ToList();
}
private void btnStopRecord_Click(object sender, EventArgs e)
{
waveInSel.StopRecording();
writer.Close();
}
private void btnStartRecord_Click(object sender, EventArgs e)
{
using (SaveFileDialog _sfd = new SaveFileDialog())
{
_sfd.Filter = "Mp3 File (*.mp3)|*.mp3";
if (_sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
MMDevice _device = (MMDevice)cboAudioDrivers.SelectedItem;
waveInSel = new WasapiLoopbackCapture(_device);
writer = new WaveFileWriter(_sfd.FileName, waveInSel.WaveFormat);
waveInSel.DataAvailable += (n, m) =>
{
writer.Write(m.Buffer, 0, m.BytesRecorded);
};
waveInSel.StartRecording();
}
}
}
}
}
can anyone help me on how to compress audio upon saving?
maybe it will be added on this part
waveInSel.DataAvailable += (n, m) =>
{
writer.Write(m.Buffer, 0, m.BytesRecorded);
};
Thanks in advance.. ;)
Try this using naudio dll
Using NAudio.Wave; Using NAudio.Wave.SampleProviders;Using NAudio.Lame
Private void WaveToMP3(int bitRate = 128){
String waveFileName = Application.StartupPath + #"\Temporal\mix.wav";
String mp3FileName = Application.StartupPath + #"\Grabaciones\ " + Strings.Format(DateTime.Now, "dd-MM-yyyy.HH.mm.ss") + ".mp3";
Using (var reader = New AudioFileReader(waveFileName))
{
Using (var writer = New LameMP3FileWriter(mp3FileName, reader.WaveFormat, bitRate))
{
reader.CopyTo(writer);
}
reader.Close();
}
}
You can't make an MP3 file by saving a WAV file with a .MP3 extension (which is what you are doing here). You will need to select an encoder available on your machine, and pass the audio through that. I go into some detail about how to do this with NAudio in this article.

Categories

Resources