|
Thanks for the reply. I was hoping for a linear barcode generator, our intended barcode scanner will not be able to read 2D
Rafferty
|
|
|
|
|
search the CodeProject articles, there are many on barcodes.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
hi all,
i am trying to export my C++ functions to C#. and i have succeeded in exporting them. while importing the functions. now to one of such functions, i want to pass two newly defined functions in C# as arguments, how should i achieve this. kindly help me.i am very badly in need of the solution to complete my project.
this is how i have implemented:
1. function exporting from C++:
extern __declspec(dllexport) bool Callregistercallback(CRTSPWrapper* pObject,funccallback fptr_video,funccallback fptr_audio,void* ptr);
where funccallback is a function pointer
2. function call in C++ test application
m_oSarixrtsp->registercallback(GetVideoPacket,GetAudioPacket,NULL);
where GetVideoPacket and GetAudioPackets are functions that are defined in the main of C++
3.function importing in C#
[DllImport("sampleclient_dll.dll", CharSet = CharSet.Ansi)]
static private extern bool Callregistercallback(IntPtr pTestClassObject,IntPtr fptr_video,IntPtr fptr_audio,IntPtr ptr);
4.function defintion in C#:
here i have defined two delegates to the functions namely Getvideopacket and getaudiopacket as follows:
public delegate void getadelegate(char[] pBuffer, int nSize);
public delegate void getvdelegate(char[] pBuffer, int nSize);
public bool registercallback([MarshalAs(UnmanagedType.FunctionPtr)]IntPtr fptr_video, [MarshalAs(UnmanagedType.FunctionPtr)] IntPtr fptr_audio, IntPtr ptr)
{
getvdelegate objv = new getvdelegate(Getvideopacket);
getadelegate obja = new getadelegate(Getaudiopacket);
return Callregistercallback(this.m_pNativeObject, fptr_video, fptr_audio, ptr);
}
5.function call from test application in C#:
testclass.registercallback(Getvideopacket,Getaudiopacket,null);
this is resulting in a compile time error stating: cannot convert a System method to System IntPtr.
Kinldy help me out please. thanks in advance.
regards
sindhu
|
|
|
|
|
There is quite alot of code here interspersed in mixed languages with non code which makes it rather difficult to find what is what.
Could you edit you post wrapping the code parts in <pre> </pre> tags (you can highlight the code and click the 'code block' link above to do this automatically)? It would be helpful if you could use different pre blocks for each language section.
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
that is unreadable, lacking PRE tags; as it involves P/Invoke, maybe this[^] helps.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
sindhumahe wrote: and i have succeeded in exporting them
Are really certain that you have succeeded?
It seems not.
First you need to ensure that your function is exported property.If you use the definition:
extern __declspec(dllexport) bool Callregistercallback(CRTSPWrapper* pObject,funccallback fptr_video,funccallback fptr_audio,void* ptr);
without appropriate definition of the function inside the library module definition file,or without setting configuration the compiler to compile the lib as C code you will be unable to call it using:
[DllImport("sampleclient_dll.dll", CharSet = CharSet.Ansi)]
static private extern bool Callregistercallback(IntPtr pTestClassObject,IntPtr fptr_video,IntPtr fptr_audio,IntPtr ptr);
That happens because by default every function is compiled as C++ code not as C code and C++ uses names decoration to avoid conflicts between functions with the same names but with different arguments.
Refer to this article for more details how to properly export your functions.
Life is a stage and we are all actors!
|
|
|
|
|
Hi,
I'm trying create a sample ActiveX control. In this process, I need to create a cab file from setup exe file using CABSDK. Please guide me. Thanks in advance.
|
|
|
|
|
This is a C# forum - for creating a cab file - see here.
modified on Wednesday, May 12, 2010 2:30 AM
|
|
|
|
|
Hi all,
Ive making trial version application. Its works fine but i do need to encrypt the data in mySQL or change the password for the respective database. Anyone can help me?
Thanks u and really appreciate ur help.
|
|
|
|
|
You need to encrypt data in csharp and store as a varchar in mysql
That's it.
For encrypting and decrypting in csharp find following article useful.
Encrypt and Decrypt Data with C#[^]
Hope this will help!
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
Hi,
I'm going to try to explain this the best I can. I have a SQL table that contains a datetime field that I am using a date picker control. This field is a verification date field for the last time the information was verified. This field can also be null if the data has not been verified. I am using a checkbox on the date picker so if the information has been verified it is checked, unverified not checked.
Since SQL has no concept of this checkbox, I have written some code that works almost perfect. It gets the current row like this:
var currentRow =
((myDataSet.ReunionRow)(((DataRowView)
(myBindingSource.Current)).Row));
and then sets the checkbox accordingly like this:
if (currentRow.IsVerifiedNull())
{
verifiedDateTimePicker.Value = DateTime.Today;
verifiedDateTimePicker.Checked = false;
Debug.WriteLine("Verified is null");
}
else
{
verifiedDateTimePicker.Value = currentRow.Verified;
verifiedDateTimePicker.Checked = true;
}
So far so good, you can navigate through the data forwards/backwards everything looks great. Then the user decides to change the verified information and doesn't click the save button on the navigator bar, scrolls away from this row and eventually comes back to it. My code happily gets the old data!
So my question is how can I tell if this row is modified to skip this logic, or how can I get the modified row?
Thank you,
Glenn
|
|
|
|
|
Check the DaraRow.DataRowState property.
Also, if you want a list with all the changes you could call DataTable.GetChanges .
Check MSDN for those properties.
Note that those properties are not static, they must be called upon an instance.
I have no smart signature yet...
|
|
|
|
|
Several years ago I taught myself a good deal of C++ but had to put it down due to time restrictions. I'd like to pick programming back up however as a hobby as I find enjoyment in building things.
That said I followed this individuals tutorial(among other things) like 4 years ago? His walkthrough in a full project start to finish was a massive educational jump for me regarding C++
http://www.stromcode.com/2008/03/01/cwin32-tutorials/[^]
The link will bring you to Stromcodes C++ Port Scanner.
I am wondering if there are similar tutorials for C# now. When I google search c# lessons/tutorials most of the lessons are extremely dry, boring, and a repeation of things I already know from my C++ days(I was never really anything beyond intermediately familiar mind you). I don't really need to do much of the beginner stuff however(short of glancing it over), and if I get stuck it's usually a few Google searches away to figuring out.
Does anyone have any recommendations on a way to quickly dive into the language while having some fun?
Also does anyone recommend John Smiley's book "Learning to Program with C#"?
Thanks everyone!
|
|
|
|
|
|
|
|
I have not personally read John Smiley's book, but you can read some comments here.
You can learn C# lesson by lesson here. It helped me a lot.
All the best
♫ 99 little bugs in the code,
99 bugs in the code
We fix a bug, compile it again
101 little bugs in the code ♫
|
|
|
|
|
I have a series of classes that make up a hierarchy of objects. I am serializing the collection to an XML file: The top level is RuleRoot :
[Serializable]
[XmlRoot("Rules")]
public class RuleRoot
{
[XmlElement("Items")]
public List<RuleGroup> Groups { get; set; }
}
Then, in Groups I have:
[Serializable]
[XmlRoot("Group")]
public class RuleGroup
{
[XmlAttribute("ID")]
public int GroupID { get; set; }
[XmlAttribute("Name")]
public string GroupName { get; set; }
[XmlAttribute("Active")]
public bool Active { get; set; }
[XmlElement("Rules")]
public List<Rule> Rules { get; set; }
}
This all works fine. But now I want to base all of my classes off of a base class:
public abstract class _ItemBase
{
public ItemType Type
{
get;
internal set;
}
public int ItemId
{
get;
internal set;
}
private _Collection<_ItemBase> _Items = new _Collection<_ItemBase>();
public _Collection<_ItemBase> Items
{
get { return _Items; }
internal set { _Items = value; }
}
}
If I do this, then each object will inherit the Items collection, so in RuleRoot I no longer need Groups, and in RuleGroup I no longer
need Rules, and so on.
The question is, how do I then serialize this?
Everything makes sense in someone's mind
|
|
|
|
|
I can give you an example from a project I was working on...though I'll warn you that it's in VB, not C#. But it should demonstrate the concepts.
I have a base class:
<Serializable()> _
Public MustInherit Class BaseClass
Private _Name As String
Private _UniqueName As String
<NonSerialized(), XmlIgnore()> _
Private _worker As System.ComponentModel.BackgroundWorker
Public Sub New(ByVal Name As String, ByVal UniqueName As String, _
Optional ByRef myWorker As System.ComponentModel.BackgroundWorker = Nothing)
_Name = Name
_UniqueName = UniqueName
_worker = myWorker
End Sub
Public Sub New()
_worker = Nothing
End Sub
Public Sub New(ByRef myWorker As System.ComponentModel.BackgroundWorker)
_worker = myWorker
End Sub
<XmlElement("Name")> _
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
End Set
End Property
<XmlElement("UniqueName")> _
Public Property UniqueName() As String
Get
Return _UniqueName
End Get
Set(ByVal value As String)
_UniqueName = value
End Set
End Property
Public Sub PerformStep()
If _worker IsNot Nothing Then
_worker.ReportProgress(50)
End If
End Sub
Public ReadOnly Property Worker() As System.ComponentModel.BackgroundWorker
Get
Return _worker
End Get
End Property
End Class
Then, I inherit that class from another class:
<Serializable()> _
Public Class Member
Inherits BaseClass
Public Sub New()
MyBase.New()
End Sub
Public Sub New(ByVal Name As String, ByVal UniqueName As String, _
Optional ByRef myWorker As System.ComponentModel.BackgroundWorker = Nothing)
MyBase.New(Name, UniqueName, myWorker)
End Sub
End Class
And as an FYI, here was another class that had a collection of class Member:
<Serializable()> _
Public Class Members
Inherits Loads
Private _members() As Member
Public Sub New()
ReDim _members(-1)
End Sub
Public Sub New(ByRef myWorker As System.ComponentModel.BackgroundWorker)
End Sub
Public Sub New(ByRef Members As ADOMD.Members, _
Optional ByRef myWorker As System.ComponentModel.BackgroundWorker = Nothing)
End Sub
Public Sub LoadMembers(ByRef Members As ADOMD.Members)
End Sub
<XmlElement("Member")> _
Public Property Members() As Member()
Get
Return _members
End Get
Set(ByVal value As Member())
_members = value
End Set
End Property
Public ReadOnly Property Count() As Long
Get
Return UBound(_members) + 1
End Get
End Property
Public Overloads ReadOnly Property Items() As Member()
Get
Return _members
End Get
End Property
Public Overloads ReadOnly Property Items(ByVal Index As Long) As Member
Get
If Index <= UBound(_members) Then
Return _members(Index)
Else
Return Nothing
End If
End Get
End Property
Public Overloads ReadOnly Property Items(ByVal Name As String) As Member
Get
For i = 0 To UBound(_members)
If _members(i).Name = Name Then
Return _members(i)
End If
Next
Return Nothing
End Get
End Property
End Class
It worked perfectly for me and deserialized perfectly.
|
|
|
|
|
Could I see the code that actually performs the serialization/deserialization?
Everything makes sense in someone's mind
|
|
|
|
|
As a preface, the object that I used actually is a multi-tiered object with the following levels:
Cube, Dimensions, Dimension, Hierarchies, Hierarchy, Levels, Level, Members, Member.
The collections (Dimensions, Hierarchies, etc...) inherit from one base class and the others inherit from the base class that I showed. They all follow the same logic I showed before, modifying the string in XMLElement in the collections.
The serialization is actually quite simple...I'll even convert it to C# for you.
Serialization.XmlSerializer serializer
try
{
serializer = new Serialization.XmlSerializer(typeof(myCubeClasses.myCubeDef));
}
catch (Exception ex)
{
}
FileStream dataFile = new FileStream("D:\\DataCubeUtilityToolbar\\DataCubeObject.xml",
FileMode.Create, FileAccess.Write,
FileShare.None);
try
{
serializer.Serialize(dataFile, myCubeType);
}
catch (Exception ex)
}
dataFile.Close();
dataFile.Dispose();
|
|
|
|
|
Thanks. Here's what I have from my test program. You code is at the bottom. The Xml file is empty after tnis runs:
static void Main(string[] args)
{
Product p1 = new Product { ItemId = 100, ProductName = "Hammer" };
Product p2 = new Product { ItemId = 101, ProductName = "Level" };
Product p3 = new Product { ItemId = 102, ProductName = "Screwdriver" };
InvoiceDetail details = new InvoiceDetail { ItemId = 10, InvoiceId = 4 };
details.Items.Add(p1);
details.Items.Add(p2);
details.Items.Add(p3);
InvoiceHeader ih = new InvoiceHeader { InvoiceDate = DateTime.Now };
ih.Items.Add(details);
Customer customer = new Customer {ItemId = 1, Name = "Frank Jones" };
customer.Items.Add(ih);
Customers customers = new Customers();
customers.Items.Add(customer);
string FileName = @"c:\myfile.xml";
XmlSerializer serializer = null;
try
{
serializer = new XmlSerializer(typeof(Test2.Customers));
}
catch (Exception ex)
{
}
FileStream dataFile = new FileStream(FileName, FileMode.Create, FileAccess.Write, FileShare.None);
try
{
serializer.Serialize(dataFile, customers);
}
catch (Exception ex)
{
}
dataFile.Close();
dataFile.Dispose();
}
Everything makes sense in someone's mind
|
|
|
|
|
The question I have then, is what does Customer's look like? And what does your base class look like?
I would think something like:
[Serializable]
[XMLRoot("Customers")]
public class Customers: _ItemBase
{
}
[Serializable]
public abstract class _ItemBase
{
[XMLAttribute("Type")]
public ItemType Type {get; set;}
[XMLAttribute("ItemID")]
public int ItemId {get; set;}
private _Collection<_ItemBase> _Items = new _Collection<_ItemBase>()
[XMLElement("Items")]
public _Collection<_ItemBase> Items
{
get {return _Items;}
set {_Items = value;}
}
}
Is that close?
You will have some problems like this though. That's because it looks like the way you've set it up, you could add an InvoiceHeader directly to Customers, or Customers to an InvoiceHeader if everything is just inherited from that base class. In order to deserialize, it's going to need a set structure, because beyond the root, I don't think you'll be able to name anything besides "Items". I could be wrong though.
|
|
|
|
|
Thats exactly the structure.
The goal here is to have a hieraarchy of objects that all inherit from a base. This way, I would know for sure that each item
has an ItemId and and Items collection. And, any method that can recieve type ItemBase could recieve an instance of any class
that inherits from it, so this means more generic code.
There's has be a way of doing this.
Everything makes sense in someone's mind
|
|
|
|
|
Well, like I said, since they are all generic classes, there would be no way for the serializer...more specifically the deserializer to know what type to put each item into.
The only two options are to make them less generic so that you can have specific XmlElements for each type. The other option is to write your own Serializer. It's not that hard to write XML code with the XML namespace.
You could probably pretty easily write your own. You could then use the typeof or gettype method to be able to specify specific Element names. With generic classes, it might not be that hard to do. You could use getType(object).Name as the Element and then add attributes and build down.
|
|
|
|
|