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
T

Tym

@Tym
About
Posts
35
Topics
15
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • calling resources
    T Tym

    Not sure if this will apply to your case, but I had a similar issue. I was simply trying to access an embedded resource of strings, no culture-specific stuff. I resolved it by qualifying the resource name with the assembly's default namespace: assembly name: MyAssembly default NameSpace: MyAssembly embedded resource: MyResources.resources ResourceManager rm = new ResourceManager("MyAssembly.MyResources", this.GetType().Assembly); string resourceValue = rm.GetString("resourceKey"); I had similar experiences with MSDN... Hope this helps. --Tym!

    C# help question

  • Drawing from CImageList onto CButton
    T Tym

    I found it. When creating the imagelist directly from the resource, the ImageList defaults to 4-bit apparently. So I has to do it the long way: CBitmap _imageBitmap _imageBitmap.LoadBitmap(IDB_BITMAP_RESOURCE_ID); CImageList _defaultImages; _defaultImages.Create(_imageWidth, _imageHeight, ILC_COLOR32|ILC_MASK, 1, 32); _defaultImages.Add(&_imageBitmap,0x0000ff00); This will create a 32-bit imagelist with a green mask from the resource.

    C / C++ / MFC graphics css database json question

  • Drawing from CImageList onto CButton
    T Tym

    I have a CButton-derived class that is owner-drawn and has data members for a pointer to a CImageList and an index to select which image in the list to display. The bitmap resource that is used to create the ImageList is 8-bit and uses green as the background color to be masked. When I draw the images onto the button, the transparency mask works great, but the rest looks bad, like it might be a 4-bit image? Yet it looks fine in the resource editor. I'm missing something crucial. Thanks in advance for any advice. Tym! Here's what I'm doing more or less: The image list is created from a resource: an 8-bit bitmap strip with a green background for the masked transparent color: CImageList _defaultImages; _defaultImages.Create(IDB_BITMAP_RESOURCE_ID, _imageWidth, 32, 0x0000ff00); The Button is created dynamically: #define BTN_STYLE BS_PUSHBUTTON|WS_VISIBLE|WS_TABSTOP|WS_CHILDWINDOW|BS_NOTIFY|BS_OWNERDRAW ... CMyButton* _myButton = new CMyButton(); _myButton->Create("",BTN_STYLE,_buttonRect,this,3999); _myButton->SetImageList(&_defaultImages); _myButton->SetImageIndex(DEFAULT_IMAGE); and I am drawing the image like so: void CMyButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC); UINT state = lpDrawItemStruct->itemState; ... // draw the bitmap: if (_imageList != NULL && _imageIndex != -1) { CPoint _location(2,2); // Offset the image if button is selected: if (state & ODS_SELECTED) _location.Offset(1,1); this->_imageList->Draw(pDC, _imageIndex, _location, ILD_TRANSPARENT); } ... }

    C / C++ / MFC graphics css database json question

  • Tag Property References?
    T Tym

    I have Class A with Properties Foo and Bar and Class B which has an indexer to an Array of Class A objects. I have a button for each element in B's array of A's. I want to refer to these A objects through the Tag property of each button: private B b = new B(2); // contructs array[2] of Class A objects, but both are null button1.Tag = b[0]; button2.Tag = b[1]; I think my problem lies in the fact that many times the elements in the array will be null, which leaves the tags as null. I would like the tag, however, to refer to the space in the array in the Class B object, so I can do something like : (A)button1.Tag = new A(FOO, BAR); thereby creating a new Class A object within b's array. Along with this I would like to be able to set the properties like: ((A)button2.Tag).Foo = NEWFOO; I come from C++ so I always think in pointers. Do I need pointers to do this, or just a different approach? Tym!

    C# c++ data-structures help question

  • byte[] cast to a string
    T Tym

    Thanks everyone for your help. Just to let you know, i ended up using encoding.default to get it working. Got a little lesson on .net text... Thanks again!

    C# question data-structures

  • byte[] cast to a string
    T Tym

    Well, that is not necessarily my ultimate solution, but I have gotten runtime errors when trying to pass the data as arrays. I may be able to, but I can't quite get everything right. I chose a string at first because it is in a struct that mimics an unmanaged struct and the original, unmanaged struct defines it as a string. The whole struct is then passed by reference in an interop call to a windows API function. When I use a string, the code runs, but the data in the string is incorrect and I get incorrect results. When I have used byte[] or char[] or even StringBuilder, I got runtime errors, saying the struct cannot converted to unmanaged.... the size cannot be determined. I might be able to do it both ways, I just need to figure out what I'm missing...:((

    C# question data-structures

  • byte[] cast to a string
    T Tym

    yeah, it's always going to be a multiple of 4 bytes, so I don't need to worry about padding. I used the UnicodeEncoding and get a different, yet still incorrect, result. I wonder if I am not declaring the struct correctly or I don't know, I feel that I am so close, but am just missing something... Thanks for your help.

    C# question data-structures

  • byte[] cast to a string
    T Tym

    The byte array is made of bytes. They do not represent characters.

    C# question data-structures

  • byte[] cast to a string
    T Tym

    I'm not too familiar with the encoders/decoders or how unicode particularly works, but my concern here is that if i have for example: byte b1=0x85; byte b2=0x7f; the data i want to actually send should be: 0x857f which I believe would be a valid unicode char. first of all, i don't want and encoder to "pad" my bytes when building a string (0x0085007f), nor do I want a decoder interpretting the bytes and apparent chars... thereby messing up the raw bits. I tried forgetting about building the array as a string and just defining it as a byte[] in the struct, but I couldn't get the marshalling right (unable to marshal struct as unmanaged type; cannot determine size...) When using a string, I am not getting a runtime error, I am just not building the string properly because I am getting incorrect results. I am open for any and all suggestions! Thanks

    C# question data-structures

  • byte[] cast to a string
    T Tym

    I am creating the byte array from individual bytes that don't represent chars, simply 8-bit values. They are being put in a struct as a string and the struct is sent by reference to a win api function (interop).

    C# question data-structures

  • byte[] cast to a string
    T Tym

    I am trying to take a byte array and cast it to a string. The closest I have come is: ASCIIEncoding.GetString Method (Byte[]) However, there is a restriction: "Any element of the bytes array that is greater than hexadecimal 0x7F is translated to a Unicode question mark ('?')." I need to keep that extra bit. Tym!

    C# question data-structures

  • StringBuilder, byte[], lpstr, interop
    T Tym

    Still can't get it to work... I have tried combinations of : byte[] char[] String StringBuilder no MarshalAs MarshalAs LPStr, ByValTStr but I get the following error each time except when building the buffer with a StringBuilder and declaring data as a string, don't need any marshalling: MIDIHDR can not be marshaled as an unmanaged structure; no meaningful size or offset can be computed. I'm thinking I just need build the string differently, so I'm gonna see what I can find on StringBuilder and hope it gets me somewhere. Thanks!

    C# help question com tutorial

  • StringBuilder, byte[], lpstr, interop
    T Tym

    Thanks for the advice. I was leaning that way, I got as far as using a byte array, but still using the marshalling attribute, which gave me a runtime error. I think you will prove to be right, it makes sense. Thanks again, I'll let ya know if it works when I get a chance to try it... Tym!

    C# help question com tutorial

  • StringBuilder, byte[], lpstr, interop
    T Tym

    Can't quite get this right. I have: [StructLayout(LayoutKind.Sequential)] public struct MIDIHDR { [MarshalAs(UnmanagedType.LPStr)] public String Data; public uint Length; public uint RecBytes; public uint User; public uint Flags; public uint Next; public uint reserve; public uint Offset; public uint Reserved; } I am having problems getting the right MIDIHDR.data value, I think. I am building the data as follows: I am building the string with a StringBuilder object. I StringBuilder.Append() anywhere from 4 to 16 bytes. I set MIDIHDR.data = StringBuilder.ToString() and MIDIHDR.Length = StringBuilder.Length When I test it by sending the MIDIHDR to a midiOutLongMsg call, I have gotten either no sound, or the same, wrong note, no matter what string I send. example bytes {153, 41, 127, 0} StringBuilder.ToString() outputs "153411270" with a length of 9 What i believe this is doing is converting the byte with a value of 153 to a string of length 3 ("153"). Is there a way to build this string as just the 4 bytes? Can I, for example, cast the byte to char before appending to the string? Am I gonna have problems with the unicode/ansi conversion in the string and it's length as its size in the struct??? Or is the marshalling of the struct really taking care of all this and I just have an error elsewhere? ( I may not understand the proper way to use midiOutLongMsg() to send multiple ShortMsg's simultaneously...) I was making headway with marshalling/interop and have been successful with everything but this.:confused: I have used the same byte data to successfully make calls to midiOutShortMsg. The bytes are actually stored in a struct of 4 bytes coerced into a union as an int. So it would be neat if I could just build the string using this int value to represent the 4 bytes, but for now I just wanna get it to work. i am going to keep playing and researching, but I thought I'd stick the question here to see if I get a nibble. Any help or insight would be greatly appreciated! Thanks! Tym! Make love, not chocolate chip cookies with nuts. At least make the cookies without nuts for crying out loud.

    C# help question com tutorial

  • c# Marshalling unmanaged type char[xx]
    T Tym

    I have the same problem. I have one char[256] unmanaged parameter and I'm only getting the first character each time. What does your function prototype look like and how are you passing your struct? Please post a solution if you find one and I will do the same. Tym!

    C# help csharp c++ question

  • interop struct types
    T Tym

    I found this on MSDN (of all places) that I think will fix my problem. Maybe it will help someone else with a similar prob: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconmarshalingclassesstructuresunions.asp[^]

    C# question csharp c++ com data-structures

  • interop struct types
    T Tym

    I have a struct to mimic a c++ struct...I have converted types as follows: C++ C# ---- ---- WORD ushort DWORD uint char[] string the imported function passes a pointer to the struct, fills it with fun-facts and gives it back more useful than before. The only thing I currently want out of this is the char[] member of the struct and things are not working out. Here's what I have done: - I am using CharSet.Auto in the structLayout and dllImport attributes. - in the function prototype : "ref STRUCTTYPE structname" - before calling the function, initializing struct by using "new" - before calling the function, initializing the string by creating a StringBuilder buffer of appropriate size and "ToString-ing" it to the struct.string member. problem is, when I call the function and access the string, it still contains the text that I used to initialize it in the first place. I haven't done enough testing to determine the problem, but I wanted to see if you have any ideas. My first question is to verify that using a c# string to represent the c++ char[] is all cool. I think it should be. [Edit]:sigh: Almost, need [MarshalAs(UnmanagedType.ByValTStr, SizeConst=256] because it is a fixed char array [/Edit] What I was thinking of while typing right now, is this: in c++ structs are reference variables. in c# they are value variables. if i wanted to pass a c# struct to a c++ function, i would use the ref modifyer. Since my function wants a pointer to the struct, should I be using something like "ref IntPtr structname" ???? is this my problem and my solution? [Edit]:doh: not quite, should work with "ref STRUCTTYPE structname"... if the struct were represented using a class, then would need [In,Out] instead of ref. See link in next post for details. Can't wait to get home and try it![/Edit] Tym!

    C# question csharp c++ com data-structures

  • calling API dll functions - types?
    T Tym

    Thanks for your help!

    C# tutorial csharp json question

  • calling API dll functions - types?
    T Tym

    I have seen several helpful examples of how to call API functions but I am confused about translating the data types. For example, I have seen DWORD parameters translated to both int and uint in c#. I am using a function that has a char[] parameter which I think should be translated as sbyte, but I'm just not sure. Any direction on a good reference for this? Tym!

    C# tutorial csharp json question

  • DLL wrapper and structs
    T Tym

    I haven't done this before, but have been researching for my own project. This is how I think it should work... define the struct in your "callee" class namespace: namespace myNS { [StructLayout(LayoutKind.Sequential)] public struct DateTimeStruct{...} class Callee{ [DllImport("CarChipSDK", EntryPoint="GetDateTime")] public static extern bool GetDateTime (out DateTimeStruct dateTime); } } in "Caller" add MyNS as reference, add new DateTimeStruct variable and then call your function, passing this variable by reference: using MyNS; ... DateTimeStruct dts; ... Callee.GetDateTime(out dts); ... // now you can use dts members: int hr = dts.hour; Let me know if this works. Tym!

    C# question csharp linux help workspace
  • Login

  • Don't have an account? Register

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