|
hiiiiiiiiiiiiiiiiiiiiii
in the ATL dll project there is one function with BYTE* Parameter.
STDMETHODIMP CMSDllServer::sum22(BYTE* aa,SHORT len)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
for(int i=1;i<len;i++)
{
aa[i]=i;
}
return S_OK;
}
in use during from this function in a windowes application c# doesnot exist no problem and array values returned to truth
byte[] Packet = new byte[5];
dllServer.sum22(ref Packet[0],5);
1,2,3,4,5
but
the same function in a webservice returned to only first index array and exist very big problem
byte[] Packet = new byte[5];
dllServer.sum22(ref Packet[0],5);
1,0,0,0,0
help me pleaseeeeeeeeeeeeeeeeeeeeeeeeeeeee
thanx
|
|
|
|
|
Check your definitions: the DLL is expecting a SHORT parameter, and you may be passing an integer. Since this is 32 bits, twice the length of a SHORT value, it is likely that the DLL is getting it as zero - in which case your Packet data will never be initialized by the function call.
BTW: Is your DLL correct?
The loop should start at zero, not one, shouldn't it?
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|
|
MY dll is truth
AND dll ATL IS CORRECT IN WEBSERVICE
BUT DLL ATL IS TRUTH IN WINDOWES APPLICATION
|
|
|
|
|
1) DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.
2) That makes no sense whatsoever!
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|
|
I am Sorry
using all lower case is considered childish but this is wrong
you can testing the condition same and make in a project Atl and using in Webservice
you see result
in the ATL dll project there is one function with BYTE* Parameter.
STDMETHODIMP CMSDllServer::sum22(byte* aa)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
for(int i=1;i<5;i++)
{
aa[i]=i;
}
return S_OK;
}
in use during from this function in a windowes application c# doesnot exist no problem and array values returned to truth
byte[] Packet = new byte[5];
dllServer.sum22(ref Packet[0]);
1,2,3,4,5
but
the same function in a webservice returned to only first index array and exist very big problem
byte[] Packet = new byte[5];
dllServer.sum22(ref Packet[0]);
:zzz:
1,0,0,0,0
help me pleaseeeeeeeeeeeeeeeeeeeeeeeeeeeee
thanx
|
|
|
|
|
Dear Sir, i am calling web service from jquery in asp.net.It's working fine on local host but is not working on remote server.When i call directly web method on remote site then web method is called but there is problem how is to call it from client side? Please help me...
|
|
|
|
|
Where is your service hosted? You need to be able to access it through the client systems.
|
|
|
|
|
I know there is a way to tell if the usb device is in use. When one application fetches one usb device, the other application is unable to get the same device handle because it already "taken" by the 1st application.
right now, my two application are able to get the same usb devices.
any suggestion on how to prevent the 2nd application from detecting or open the usb device that is already taken by the other application?
|
|
|
|
|
Use a "Mutex".
Before "taking" the usb device, each application tries to create a Mutex.
If the Mutex is created, the device was free; else the "other" app is using the device (because "it" has already created the Mutex).
|
|
|
|
|
hmm I don't think Mutex would do. Tried to understand Mutex.
but what about with this method?
DeviceHandle = CreateFile(DevicePath, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, ref Security, OPEN_EXISTING, 0, 0);
Tried to understand it a bit too. If I use 0 in place of FILE_SHARE_READ | FILE_SHARE_WRITE, would this be a good idea?
|
|
|
|
|
A Mutex is simply a way to communicate a semaphor between processes.
If you're considering CreateFile, then you should go to the Windows API forum.
|
|
|
|
|
I'm building a vcf editor and there are approximately 4k contacts in the particular file I'm using.
I've gotten to contact 1000 in a little over 10 minutes, so I'm wondering what a faster way to go about parsing these would be?
The file is only 1.2mb and the function is below. Maybe the slow speed is in the gui update and not stream reader, not sure?
using (StreamReader reader = new StreamReader(filePath))
{
List<string> vcfFile = new List<string>();
string readLine;
while ((readLine = reader.ReadLine()) != null)
{
vcfFile.Add(readLine);
}
int count = 0;
foreach (string line in vcfFile)
{
if (line == "BEGIN:VCARD")
{
count = count + 1;
tbxOutput.Text += (count + ".) ").ToString();
}
tbxOutput.Text += line + System.Environment.NewLine;
if (line == "END:VCARD")
{
tbxOutput.Text += System.Environment.NewLine + System.Environment.NewLine;
}
Application.DoEvents();
}
}
|
|
|
|
|
I take it the UI is freezing while this runs in the foreground?
If you are not runnning this as a separate thread, run it as a background worker and update the textbox via a delegate.
Also get rid of the Application.DoEvents(); too as it is considered to be bad practise-> clickety[^].
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
Thanks for the reply.
I temporarily used the application.doevents() because I couldn't tell if it was doing anything.
I have since thrown this in, but it is still very very slow, especially after it gets past the first few hundred entries. The initial few hundred entries are at a speed I would expect.
I will try the workthread as well.
if (count % 50 == 0)
{
Application.DoEvents();
tbxOutput.SelectionStart = tbxOutput.Text.Length;
tbxOutput.ScrollToCaret();
tbxOutput.Refresh();
}
|
|
|
|
|
Part of your slow down is in the continual appending to tbxOutput.Text. Rather than using a TextBox, use a ListBox instead. Alternatively, read it all into a StringBuilder and blast it out in one go with a ToString(). And yes, move this into a background thread.
|
|
|
|
|
Great idea, that really sped things up to about 20 seconds!
|
|
|
|
|
This code is very quick in case someone else can learn from my mistake, thank you both for helping me through this.
private void vcfProcessor(object filePathObj)
{
try
{
string filePath = filePathObj.ToString();
using (StreamReader reader = new StreamReader(filePath))
{
List<string> vcfFile = new List<string>();
string readLine;
while ((readLine = reader.ReadLine()) != null)
{
vcfFile.Add(readLine);
}
int count = 0;
foreach (string line in vcfFile)
{
if (line == "BEGIN:VCARD")
{
count = count + 1;
lbxOutput.Items.Add(count + ".) ").ToString();
}
lbxOutput.Items.Add(line + System.Environment.NewLine);
if (line == "END:VCARD")
{
lbxOutput.Items.Add(System.Environment.NewLine);
}
if (count % 50 == 0)
{
tbxContactNumber.Text = count.ToString();
Application.DoEvents();
}
}
tbxContactNumber.Text = count.ToString();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + System.Environment.NewLine + ex.Source + System.Environment.NewLine + ex.TargetSite + System.Environment.NewLine + ex.StackTrace + System.Environment.NewLine + System.Environment.NewLine);
}
}
|
|
|
|
|
As others have said, perform this function on a background thread, update your controls using Invoke/BeginInvoke and get rid of the DoEvents
|
|
|
|
|
I'm trying to add an interface, but it's causing havoc with my ProgressBar update events (My progress bar event is null so my progress bar never gets updated). I have the following older link about it: [^]
The progress bar works where it doesn't use events in Generic, but it's not working where I'm using the events in CR5_new and CR5_Comm. As you can see below, when I get to RaiseProgressChange in my CR5_new class, the event is null. I can't figure out why it's null. I'm not very good with events, and throwing in the interface (the iCR_Comm interface is new) doesn't help, since I'm not very good at interfaces either. I removed unrelated code, so hopefully this post isn't missing important definitions. I realize that this doesn't look familiar to you and is a lot of info, but any help would be appreciated. If anyone is mean, I'm not going to upvote that comment. There are very specific project related reasons that these are all separate vs projects. (re-use, multiple CRx's, multiple CRx_comm's, and numerous dynamic data classes that give extra control info to the Generic class.) Everything works (programming, write, read, through CR5_Comm class), so don't focus on that. It's just the events that update the progress bar that don't work. Names of classes have been changed enough that they don't give away our information, but still resemble my code.
My code looks like this now (all separate vs projects):
vs project: crTool
frmUserForm.cs:
using USB_Comm;
namespace CRWriter
{
public partial class frmUser:Form
{
public frmUser(string dllSelected, TemplateHandlerApplication.Templates.TEMPL[] template, string dll, Site.Site.SITE cert0)
{
programDll = dllSelected;
templateArr = template;
itsDll = dll;
cert = cert0;
InitializeComponent();
CreateSubForms();
}
private void CreateSubForms()
{
cb = new CrComm();
int errValue = cb.FindUsbHid(ref HWndBoxID);
for (int i = 0; i < cb.cbInfos.Length; i++)
{
iCRComm cb1 = null;
if (controls[i] == null)
{
CRComm_Factory.CRCommFactory factory = new CRComm_Factory.CRCommFactory();
int type = factory.DetermineCR_Type(programDll);
try
{
cb1 = factory.GetCRComm(type);
controls[i] = gen.GetProgramControl(cb1, programDll, templateArr, itsDll, cert, i, cb1.GetBoxID(i), this);
}
...
}
}
}
}
}
vs project: Generic
GenericPC.cs
using USB_Comm;
namespace GenericCW
{
public partial class GenericPC: UserControl
{
public GenericPC() {InitializeComponent();}
public Control GetPC(iCRComm cbInstance, string dllSelected, TemplateHandlerApp.Templates.TEMPL[] template, string dll, Site.Site.SITE cert0, int slaveIndex, int boxID, Form theParent)
{
cr = factory.GetCR(type, slaveIndex);
cr.ProgressChanged += new ProgressChangeHandler2(updateProgressBar);
}
private int writeResultCheck(byte [] writeDat, byte [] statusDat, byte [] dataDumpWriteCheck)
{
for (int count = 0; ((count < max) && (!done)); count++)
{
if(((count % 24) == 0) || (count == max-1))
updateProgressBar(count, SlaveIndex);
}
}
}
private void updateProgressBar(int n, int id)
{
if (id == SlaveIndex)
{
pb_Progress.BeginInvoke(
new Action(() =>
{
pb_Progress.Value = n;
}
));
}
}
}
}
vs project: cr5_new
CR5_new.cs:
using USB_Comm;
namespace CR5_new
{
public class CR5:iCR
{
[STAThread]
static void Main()
{
}
public event ProgressChangeHandler2 ProgressChanged;
public CR5(int slaveIndex)
{
SlaveIndex = slaveIndex;
}
public int ProcessTagWrite(ref byte[] WriteDat, bool isFastProgramMode)
{
AttemptWrites();
}
private int AttemptWrites()
{
for (int i = 0; i < (max); i++)
{
if (((i % 28) == 0) || (i == max-1))
RaiseProgressChange(i, SlaveIndex);
}
}
private void RaiseProgressChange(int progress, int id)
{
if (ProgressChanged != null)
{
ProgressChanged(progress, id);
}
}
vs project: icr
iCR.cs:
using USB_Comm;
public interface iCR
{
event ProgressChangeHandler2 ProgressChanged;
...
}
vs project: icrComm
iCRComm.cs:
public delegate void ProgressChangeHandler2(int progress, int id);
public interface iCRComm
{
event ProgressChangeHandler2 ProgressChanged;
int ReadTag(ref byte[] dataDumpWriteCheck);
}
vs project: cr5_comm_new
CR5_Comm.cs:
namespace USB_Comm
{
public class CrComm:iCRComm
{
public event ProgressChangeHandler2 ProgressChanged;
private void RaiseProgressChange(int progress, int id)
{
if (ProgressChanged != null)
{
ProgressChanged(progress, id);
}
}
public int ReadTag(ref byte[] byteData, int usbIndex)
{
for (int cell = 0; cell < max; cell++)
{
if (((cell % 28) == 0) || (cell == max-1))
{
RaiseProgressChange(cell, usbIndex);
}
}
}
}
}
}
}
|
|
|
|
|
public Control GetPC(iCRComm cbInstance, string dllSelected, TemplateHandlerApp.Templates.TEMPL[] template, string dll, Site.Site.SITE cert0, int slaveIndex, int boxID, Form theParent)
{
cr = factory.GetCR(type, slaveIndex);
cr.ProgressChanged += new ProgressChangeHandler2(updateProgressBar);
}
What type is "cr"? And what does the factory return? Btw, your naming isn't very helpful here. Any way we could translate what you're trying to achieve to a simple console-app? Makes it easier to focus on the problem itself, without having to worry about the rest of the app.
Why does the CR5_new class have a Main method? It's not the entry-point for your app, is it?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks for the input, Eddy. I guess it's a good idea to try and put it in a simple console app. It might be crucial that I'm jumping through separate vs projects etc, so I left it as-is. I'm not sure why CR5 has a main. It's mostly just a dll and not a form, unlike a lot of my other classes.
cr is an iCR type. It looks like this in the factory:
public iCR GetCR(CRType type, int slaveIndex)
{
iCR cr = null;
switch (type)
{
case CRType.CR5:
cr = new CR5_new.CR5(slaveIndex);
break;
case CRType.CR6:
cr = new CR6.CR6(slaveIndex);
break;
default:
throw new ArgumentException(string.Format("A CR of type {0} cannot be found", Enum.GetName(typeof(CRType), type)));
}
return cr;
}
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplicationXXIV
{
enum CRType { CR5, CR6 }
public delegate void ProgressChangeHandler2(int progress, int id);
public interface iCR
{
event ProgressChangeHandler2 ProgressChanged;
}
public class CR5 : iCR
{
public int SlaveIndex { get; set; }
public event ProgressChangeHandler2 ProgressChanged;
public CR5(int slaveIndex)
{
SlaveIndex = slaveIndex;
}
public int ProcessTagWrite()
{
AttemptWrites();
return 0;
}
private void AttemptWrites()
{
for (int i = 0; i < (10); i++)
{
RaiseProgressChange(i, SlaveIndex);
}
}
private void RaiseProgressChange(int progress, int id)
{
if (ProgressChanged != null)
{
ProgressChanged(progress, id);
}
}
}
class GenericPC
{
public object GetPC()
{
var cr = Program.GetCR(CRType.CR5, 0);
cr.ProgressChanged += new ProgressChangeHandler2(updateProgressBar);
(cr as CR5).ProcessTagWrite();
return cr;
}
private void updateProgressBar(int n, int id)
{
Console.WriteLine(String.Format("Progress: {0}\tid:{1}", n, id));
}
}
class Program
{
static void Main(string[] args)
{
var npc = new GenericPC();
npc.GetPC();
Console.ReadKey();
}
public static iCR GetCR(CRType type, int slaveIndex)
{
iCR cr = null;
switch (type)
{
case CRType.CR5:
cr = new CR5(slaveIndex);
break;
case CRType.CR6:
cr = null;
break;
default:
throw new ArgumentException(string.Format("A CR of type {0} cannot be found", Enum.GetName(typeof(CRType), type)));
}
return cr;
}
}
} First things first; place the cursor on the word ProgressChangeHandler2 and press F2 (or Ctrl-R, Ctrl-R) and rename that to something without a number
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Good start. The Cr5_Comm class is missing from that. Good idea for ProgressChangeHandler to lose the 2. If you don't have the iCR_Comm interface, it's like I never made my changes at all.
|
|
|
|
|
To use the other interface, the CR5 class would need to inherit from it and implement it.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplicationXXIV
{
enum CRType { CR5, CR6 }
public delegate void ProgressChangeHandler2(int progress, int id);
public interface iCRComm
{
event ProgressChangeHandler2 ProgressChanged;
int ReadTag(ref byte[] dataDumpWriteCheck);
}
public class CR5 : iCRComm
{
public int SlaveIndex { get; set; }
public event ProgressChangeHandler2 ProgressChanged;
public CR5(int slaveIndex)
{
SlaveIndex = slaveIndex;
}
public int ReadTag(ref byte[] dataDumpWriteCheck)
{
Console.WriteLine(String.Format("Data: {0}", dataDumpWriteCheck));
return 0;
}
private void RaiseProgressChange(int progress, int id)
{
if (ProgressChanged != null)
{
ProgressChanged(progress, id);
}
}
}
class GenericPC
{
public iCRComm GetPC()
{
var cr = Program.GetCR(CRType.CR5, 0);
cr.ProgressChanged += new ProgressChangeHandler2(updateProgressBar);
byte[] b = null;
cr.ReadTag(ref b);
return cr;
}
private void updateProgressBar(int n, int id)
{
Console.WriteLine(String.Format("Progress: {0}\tid:{1}", n, id));
}
}
class Program
{
static void Main(string[] args)
{
var npc = new GenericPC();
npc.GetPC();
Console.ReadKey();
}
public static iCRComm GetCR(CRType type, int slaveIndex)
{
iCRComm cr = null;
switch (type)
{
case CRType.CR5:
cr = new CR5(slaveIndex);
break;
case CRType.CR6:
cr = null;
break;
default:
throw new ArgumentException(string.Format("A CR of type {0} cannot be found", Enum.GetName(typeof(CRType), type)));
}
return cr;
}
}
}
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Can CR5 inherit from both iCR and iCRComm?
|
|
|
|
|