Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
D

dfn

@dfn
About
Posts
27
Topics
15
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Entity Framework: EDM assigns primary key to view randomly (or so it seems)
    D dfn

    Thanks for your reply. If this is the case, how would I get around it? If I set the column to NOT be a key, I get a mismatch error, suggesting that both fields (EDM and my DB) must be keys.

    C# question csharp help

  • Entity Framework: EDM assigns primary key to view randomly (or so it seems)
    D dfn

    Hi, I made a view from a few tables. I then imported that view into my Entity Data Model. The EDM assigned Entity Key = true to a column in the view that is not a primary key (the column is not a primary key in the view, and it is not a primary key in the table the view gets it from). Why does the EDM do this? It assigned Entity Key = true to a value that IS an actual primary key (in the table my view looks at) and also to a value that ISN'T a primary key. I can't figure this out. Can anyone help me out? TIA PS -- I apologize if this is not the right forum, but since in the EDM I am dealing with C# code, I thought I'd post it here.

    C# question csharp help

  • Stored Procedure that returns data with Entity Data Model not working
    D dfn

    Thanks for the help. At least that ? isn't a mystery now. Nothing glaringly wrong with what I'm doing though? I still can't figure out why I can't call the function import I made for that stored proc...

    C# database question csharp dotnet visual-studio

  • Stored Procedure that returns data with Entity Data Model not working
    D dfn

    Hi. My solution (working in VS 2008) has a C# console app, and a C# web service. The service has an entity data model. It has numerous stored procedures. For one of the stored procs, which just returns data (SELECT blah blah FROM...), I added a function import called "Iservice." I saved all, then in my console app, updated the service reference to my C# service. Now, in my console app, I am trying to do the following:

    myEnts db = new myEnts(new Uri("http://localhost:3811/isr.svc"));

    foreach(st_service sr in db.Iservice(false))
    Console.WriteLine("Number#: {0} " + sr.num);

    This doesn't work. "Iservice" is the name of the function import I created and I can see it in the object browser, but when I look at the service reference, I can't see it in the object browser. The compiler doesn't like "db.Iservice(false)" and the message is that myEnts from the service reference does not containt a definition for "Iservice." So when I am in the service project, and look at the object browser, I can see Iservice - however when I look at the service reference in the object browser, from the console project, I do not see Iservice. How come this happens? How can I fix this? I tried saving, closing, and reloading MSVS2008, I tried updating the service reference multiple times. I googled for examples of calling stored procs in the EDM, and tried different ways of calling it as shown here: http://blogs.microsoft.co.il/blogs/gilf/archive/2009/03/13/mapping-stored-procedure-results-to-a-custom-entity-in-entity-framework.aspx[^] http://blogs.msdn.com/bags/archive/2009/03/13/entity-framework-modeling-select-stored-procedures.aspx[^] http://blogs.msdn.com/adonet/archive/2007/09/14/how-to-map-stored-procedures-using-the-ado-net-entity-framework.aspx[

    C# database question csharp dotnet visual-studio

  • problem with HttpRequest.QueryString
    D dfn

    I have a problem with HttpRequest.QueryString. There is an XML string that contains something like the following: 8+ As you probably guessed, the "+" is the problem :) I want to get that XML string from QueryString, however, the "+" appears as a " " (space), not a "+". I have tried the following: NameValueCollection coll = Request.QueryString; XMLstring = coll.Get("XMLstr"); // result: XMLstring = "8 " XMLstring = Request.QueryString["XMLstr"]; // result: XMLstring = "8 " XMLstring = Request.QueryString.Get("XMLstr"); // result: XMLstring = "8 " XMLstring = HttpUtility.HtmlDecode(Request.QueryString["XMLstr"]); // result: XMLstring = "8 " XMLstring = HttpUtility.HtmlDecode(Request.QueryString.Get("XMLstr")); // result: XMLstring = "8 " In all of the above cases, XMLstring is a string (string XMLstring = ""; ). I realise I can just search XMLstring and replace the space with the plus sign. I don't want to do that though. Also, this isn't my code, and I have no idea why XML is in QueryString nor if it should be there, never worked with asp or done web stuff in C#, but it has to stay like this for the moment, and I have to somehow extract that + sign. Any help or advice is appreciated. Thanks.

    C# help csharp xml

  • connecting labels on a panel with lines
    D dfn

    Thank you! I don't know why it doesn't work in MouseUp, but having it redraw during movement (in MouseMove) works. Well, kinda, but I have the main problem solved. Thanks again for your help!

    C# question database help

  • connecting labels on a panel with lines
    D dfn

    oops, sorry:

        private void my\_lbl\_MouseUp(object sender, MouseEventArgs e)
        {
            drag = false;
            Point temp;
    
            for (int i = 0; i < Links.Count; i++)
            {
                if (Links\[i\].p1 == old\_point1 || Links\[i\].p1 == old\_point2)
                {
                    Links\[i\].p1.X += e.X;
                    Links\[i\].p1.Y += e.Y;
                }
    
                if (Links\[i\].p2 == old\_point1 || Links\[i\].p2 == old\_point2)
                {
                    Links\[i\].p2.X += e.X;
                    Links\[i\].p2.Y += e.Y;
                }
            }
        }
    
    C# question database help

  • connecting labels on a panel with lines
    D dfn

    Hi. I have an app that reads the DB, and then populates a panel in my program with a bunch of labels. The user is able to drag those labels anywhere on the panel (basically drag and drop, using MouseDown, MouseMove, MouseUp). Some of those labels have "links" between them which I'd like to represent with lines, connecting one label to another. I'd also like the lines to be redrawn to the new label location once a label is moved by a user. What is the easiest way to do this? I tried maintaining a list of labels and their links, and updating the link, then just redrawing lines. However, in my MouseUp function, where the links are updated (mouse up means the user "dropped" the label and so it has a new location), the x,y coords of e are always zero: [pre] private void my_lbl_MouseUp(object sender, MouseEventArgs e) { drag = false; Point temp; for (int i = 0; i < Links.Count; i++ ) { if (Links[i].p1 == old_point1 || Links[i].p1 == old_point2) { Links[i].p1.X += e.X; Links[i].p1.Y += e.Y; } if (Links[i].p2 == old_point1 || Links[i].p2 == old_point2) { Links[i].p2.X += e.X; Links[i].p2.Y += e.Y; } } } [/pre] Can anyone tell me why e.X and e.Y are always zero when a user moves the labels? Or an easier way to do what I've described above? Any help or advice is appreciated.

    C# question database help

  • struct containing array of pointers to struct (C dll to C#)
    D dfn

    Hi. In C dll, there is a struct that contains an array of struct pointers. I do not know how to represent that in C#. That's my problem. Here is the relevant C code:

    struct vector
    {
    uint elem_count;
    uint size;
    int (*cmp)(const void *, const void *);
    void *table;
    };

    typedef struct vector VECTOR;

    #define CTABLE VECTOR
    #define CSTATS VECTOR

    struct cstream
    {
    int mode;
    int byte_count;
    uchar *buff;
    int buff_len;
    int buff_pos;
    int bit_pos;
    bool growable;
    bool prepared;
    CTABLE *table[2];
    CSTATS *stats[3];
    uchar last_mode;
    int last_mode_offset;
    };

    And here is the C# code:

    [UnmanagedFunctionPointer(CallingConvention.Winapi) ]
    unsafe public delegate int cmp(IntPtr a, IntPtr b);

        \[StructLayout(LayoutKind.Sequential, Pack = 1)\]
        unsafe public struct VECTOR
        {
            public uint elem\_count;
            public uint size;
            public uint elem\_size;
            \[MarshalAs(UnmanagedType.FunctionPtr)\]
            public cmp cp; //C-func: public int (\*cmp)(const void \*, const void \*);
            public IntPtr table;
        }
    
        \[StructLayout(LayoutKind.Sequential, Pack = 1)\]
        unsafe public struct CSTREAM
        {
            public int mode;
            public int byte\_count;
            public IntPtr buff;
            public int buff\_len;
            public int buff\_pos;
            public int bit\_pos;
            public bool growable;
            public bool prepared;
            public VECTOR\[2\]; // CTABLE \*table\[TTABLE\_COUNT\];
            public VECTOR\[3\]; // CSTATS \*stats\[STATS\_COUNT\];
            public byte last\_mode;
            public int last\_mode\_offset;
        }
    
        \[DllImport("compr.dll")\]
        public static extern IntPtr screate(); // this function in C dll returns pointer to struct
    
        \[DllImport("compr.dll")\]
        public static extern IntPtr tcreate(); // this function in C dll returns pointer to struct; 
    

    Now, I know how to get the IntPtr to a struct. For example:

    MyClass.VECTOR stext = new MyClass.VECTOR();
    IntPtr st = MyClass.screate();
    stext = (MyClass.VECTOR)Marshal.PtrToStructure(st, typeof(MyClass.VECTOR));

    However, I do not know how to represent, or work with, "CTABLE *table[2];" or "CSTATS *stats[3];" from the struct in C, in the C# struct (CSTREAM). Does anyone know how to do this? Thank you for any help.

    C# help tutorial csharp graphics data-structures

  • C# pointer to struct using C dll
    D dfn

    Sorry, here it is. C code:

    #if defined(WIN32)

    define DLL_EXPORT __declspec(dllexport)

    #else

    define DLL_EXPORT /**/

    #endif

    #ifdef __cplusplus
    extern "C" {
    #endif

    struct vector
    {
    	uint elem\_count; /\* number of items in the vector \*/
    	uint size;		/\* size of the vector \*/
    	uint elem\_size; /\* element size \*/
    	int (\*cmp)(const void \*, const void \*);
    	void \*table;
    };
    
    typedef struct vector VECTOR;
    #define CSTATS VECTOR
    
    //function definition:
    DLL\_EXPORT CSTATS \*screate(); // returns CSTATS pointer
    ...
    

    #ifdef __cplusplus
    }
    #endif

    C# code:

    \[UnmanagedFunctionPointer(CallingConvention.Winapi)\]
    unsafe public delegate int cmp(IntPtr a, IntPtr b);
    
    \[StructLayout(LayoutKind.Sequential, Pack = 1)\]
    unsafe public struct VECTOR
    {
        public uint elem\_count;
        public uint size;
        public uint elem\_size;
        \[MarshalAs(UnmanagedType.FunctionPtr)\]
        public cmp cp; //C-func: public int (\*cmp)(const void \*, const void \*);
        public IntPtr table;
    }
    
    \[UnmanagedFunctionPointer(CallingConvention.Winapi)\]
    unsafe public delegate VECTOR screate();
    
    \[DllImport("myTest.dll", EntryPoint = "screate", ExactSpelling = true)\]
    public static extern screate scrt();
    
    C# help question csharp graphics

  • C# pointer to struct using C dll
    D dfn

    Hi. I need to basically have an equivalent C# struct to my C struct. I need to make a pointer to it. This is the relevant code: C code: #if defined(WIN32) # define DLL_EXPORT __declspec(dllexport) #else # define DLL_EXPORT /**/ #endif #ifdef __cplusplus extern "C" { #endif struct vector { uint elem_count; /* number of items in the vector */ uint size; /* size of the vector */ uint elem_size; /* element size */ int (*cmp)(const void *, const void *); void *table; }; typedef struct vector VECTOR; #define CSTATS VECTOR //function definition: DLL_EXPORT CSTATS *screate(); // returns CSTATS pointer ... #ifdef __cplusplus } #endif C# code: [UnmanagedFunctionPointer(CallingConvention.Winapi)] unsafe public delegate int cmp(IntPtr a, IntPtr b); [StructLayout(LayoutKind.Sequential, Pack = 1)] unsafe public struct VECTOR { public uint elem_count; public uint size; public uint elem_size; [MarshalAs(UnmanagedType.FunctionPtr)] public cmp cp; //C-func: public int (*cmp)(const void *, const void *); public IntPtr table; } [UnmanagedFunctionPointer(CallingConvention.Winapi)] unsafe public delegate VECTOR screate(); [DllImport("myTest.dll", EntryPoint = "screate", ExactSpelling = true)] public static extern screate scrt(); Now, here is the problem. The C code I want to emulate in C# is this: CSTATS *st; st = screate(); In C#, I tried: VECTOR* st = screate(); VECTOR* st = scrt(); and so on... The error I get is: error CS0208: Cannot take the address of, get the size of, or declare a pointer to a managed type ('myDll.VECTOR') So I am looking for help. What is the equivalent C# code that I need, in order to achieve "CSTATS *st; st = screate();" in C? Thank you for any help.

    C# help question csharp graphics

  • using dll created by MinGW in C# code
    D dfn

    Hi. I have created a dll from C code using MinGW. I try using it in my C# code, the code compiles, but the executable always hangs. If I use the dll in plain C code, the executable runs fine. I've gone through several tutorials and the dll always hangs if I try to run my compiled C# code. For reference, the last tutorial I attempted was this one. What am I doing wrong? How can I access a dll, compiled with gcc under MinGW, in my C# code?

    C# question csharp html tutorial

  • making .dll file in VC++ from C code written in unix
    D dfn

    Hello. I have a buncha files that were written in C in unix. It uses a few libraries that I don't have using Visual Studio 2005 (Win). How do I compile the files into a .dll under VC++ in Win?

    C / C++ / MFC question csharp c++ visual-studio

  • C# app using C code written in Linux
    D dfn

    Hi. I have a C# app that I wrote in Visual Studio, in Windows. There are a few libraries that my code needs to use, and they were written in C, in Linux. I am totally new to this. Is there an easy way to either convert the C code to C#, or to allow my C# app to access the C code? I tried compiling the C code in visual studio, but some of the libraries included are *nix based/specific, and I don't know their counterparts in Visual Studio under Windows.

    C# csharp visual-studio linux question

  • parsing a string with DateTime.ParseExact
    D dfn

    Thanks all for the replies! I ended up using the overloaded ToString method.

    C# help regex json question

  • parsing a string with DateTime.ParseExact
    D dfn

    Hi. I am having trouble parsing a string into the format I want. Basically, I want the string to end up being "MMdd" where MM is the month (with a leading zero if necessary) and dd is the day (with a leading zero if necessary). This is what I have tried: String today = DateTime.Today.Date.ToShortDateString(); String pattern = "MMdd"; DateTime dt_today = DateTime.ParseExact(today, pattern, null); // line 3 today = dt_today.ToString(); Console.WriteLine("today's date is: " + today); The problem is that my program crashes once run. If you look at the third line, in place of null, I have tried sending: System.Globalization.CultureInfo.InvariantCulture, System.Globalization.CultureInfo.CurrentCulture Both yielded the same result. I have also tried using "Now" instead of "Today" in the first line. What am I doing wrong? I'd appreciate any help.

    C# help regex json question

  • one object's private variable affecting another object's, but it shouldn't [modified]
    D dfn

    Hi. My problem is the following. I have a class that contains a "MakeByteArray" function. I have many objects of that class. Inside that function, I have a private variable, that is NOT static. It seems that when I put all these objects in other objects, and then into a list, and I iterate through every object, the PRIVATE variable that i use in "MakeByteArray" is altered depending on what the value was in the previous object. This makes no sense since the objects don't know about each other, and the variable is not static. In short, the following happnes: Print contents of object 1; object 1 has private variable "priv_var" that is a short and has a value of "X"; correct contents printed Print contents of object 2; object 2 has private variable "priv_var" that is a short and has a value of "Y"; incorrect contents printed; "Y" should have been printed, but, "Y+X" was printed instead (note that "X" is the value of "priv_var" in object 1) OR, if I reset priv_var to 0 at end of MakeByteArray() in object 1, then sometimes the value (0) carries over to object 2's priv_var (when it shouldn't) How do I know that object 2's "priv_var" got the value "Y+X" from object 1, and NOT from somewhere else? I did tests. When object 1's value changed, so did object 2's. I tried many different (short) values, and the results were the same. However, this doesn't happen always. I know *when* it happens, but I don't know *why*. I this summarizes my problem, however, if you want to see more (very long), including code, scroll down. Oh, forgot to mention, I am using Visual Studio 2005, Windows XP, on an intel machine. I'd appreciate any help with this. Thank you. ----------------------------------------------------------------------------------------------- Before you start, I apologize in advance for the formatting (or lack of) of my code. Now, my code. This is the code for the class whose objects are put into another object. namespace ConsoleApplication1 { public class MyPara : MyFormat { public static long totalSum = 0; // public for testing purposes protected short rc; public MyPara() { /* various variables initialized here */ rc = 0; } /* more constructors here; all of them do rc = 0; multiple (irrelevant) functions here as well; */ public bool IncRc() { rc++; } public byte[] MakeByteArray() { shor

    C# help question csharp c++ visual-studio

  • porting c code and crc32
    D dfn

    Hi. A few quick questions: Does C# have any function that will compute crc32? How can I port C code into C#? Do I have to rewrite it, or is there a quicker way?

    C# question csharp

  • generic functions
    D dfn

    I would like to know how to implement generic functions. I have a few classes: CdRecord, BookRecord, Record, and RecordManager. CdRecord inherits from Record. BookRecord inherits from Record. In my RecordManager class, I have a bunch of functions. Two of the functions in RecordManager read info from a table in an SQL DB. rough code: using... namespace MyProject { class RecordManager { List CDrecords = new List(); List BOOKrecords = new List(); public void readBooks() { // connect to DB // fill BOOKrecords with entries from table } public void readCds() { // connect to DB // fill CDrecords with entries from table } } } Now, once I've filled CDrecords and BOOKrecords, I need a function that will split them, and re-arrange the order of the records. I realise I can make one function that takes a List parameter and one function that takes a List parameter, but I'd prefer to have one function be able to handle them both. I also know that I can just send an extra parameter (int i for example) that indicates what type i am working with (if i == 1, BookRecord list, etc). However, I don't like this method either. In the future, I may end up with many more classes that inherit from Record, that I'll have lists of that need to be split, and I don't want to have a function for each type because I may end up with 20 redundant functions. Similarly, I don't want to send an extra parameter because of readability (if i == 1, if i == 2, .... if i == 20). How do I make one function that is able to take a paramater of type List where T can be CdRecord or BookRecord? I have tried the following, and it does not work: public void SplitRecords(List records, int start, int end) { //some code for(int i = start; i <= end; i++) { //some code records[i].memberFunction(); //some code } } The reason it doesn't work is because "memberFunction()" is a function of Record (which is inherited by BookRecord and CdRecord) but "T" does not have a definition for "memberFunction()" How do I correct this? Could I be experiencing problems because I am trying to use classes I wrote with generics, rather than int/short/etc.? Thanks in advance for any assistance!

    C# database tutorial question

  • problem with List and FindAll()
    D dfn

    First, I apologize. My code was not correct, and I'm sure that added to the confusion. Now, al is ArrayList al, and the reason I need al[0] is to see if two ArrayLists contained in "allEntries" have the same value stored in index 0. I have tried it when al[0] and al[1] contain the same values, and when they contain different values. The result is the same, ie, in the anonymous function, al[0] sometimes gives the values of al[1]. Here is my code again: List allEntries = new List(); byte id0 = 0, id1 = 1; byte sid1 = 16, sid2 = 88, sid3 = 100; ArrayList entry1 = new ArrayList(); ArrayList entry2 = new ArrayList(); ArrayList entry3 = new ArrayList(); entry1.Add(id0); entry1.Add(sid1); entry1.Add("John"); entry1.Add("Doe"); entry2.Add(id1); entry2.Add(sid2); entry2.Add("Jane"); entry2.Add("Doe"); entry3.Add(id0); // notice index 0 of entry3 and entry1 contains id0 entry3.Add(sid3); entry3.Add("Joe"); entry3.Add("Doe"); allEntries.Add(entry1); allEntries.Add(entry2); allEntries.Add(entry3); for (byte i = 0; i < 2; i++) { List sameIdEntries = allEntries.FindAll(delegate(ArrayList al) { return((byte)al[0] == i); }); // do stuff } // for Any help is appreciated!

    C# help question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups