type-casting

Typecast:LPCTSTR to Char * for string concatenate operation

Can u Give solution for this code of typecasting, LPCTSTR(here lpsubkey) to Char* for below code snippet , char* s="HKEY_CURRENT_USER\\"; strcat(s,(char*)lpSubKey); printf("%S",s); here it makes error of access violation ,so what will be the solution for that?. ...thanks in advance ...

Using get type and then casting to that type in csharp

I have code like: var t = SomeInstanceOfSomeClass.GetType(); ((t)SomeOtherObjectIWantToCast).someMethodInSomeClass(...); That won't do, the compiler returns an error about the (t) saying Type or namespace expected. How can you do this? I'm sure it's actually really obvious.... ...

How do I do this clever casting in C?

You can see what i'm trying to do below: typedef struct image_bounds { int xmin, ymin, xmax, ymax; } image_bounds; #define IMAGE_BOUNDS(X) ((image_bounds *)(X)); typedef struct { image_bounds bounds; float dummy; } demo; int main(void) { demo my_image; /* this works fine */ ((image_bounds *)(&my_image))->xmin...

Groovy type conversion

Hi, In Groovy you can do surprising type conversions using either the as operator or the asType method. Examples include Short s = new Integer(6) as Short List collection = new HashSet().asType(List) I'm surprised that I can convert from an Integer to a Short and from a Set to a List, because there is no "is a" relationship between t...

Can I get Actionscript3 to type cast Numbers and ints in XML files as numbers and ints?

Everything seems to be a string right now & that kinda ruins the whole xml as an internal data structure thing, I don't need a big tree of string I need typed data :-/ Are there any changes I can make to either my XML files or my AS3 code that will force it to cast ints as ints and Numbers as Numbers? Or maybe some kind of type schema I ...

Is there any difference between type casting & type conversion?

Is there any difference between type casting & type conversion in c++. ...

C#: Convert a string to an object reference.

Basically a button's tag property is the name of an existing combobox which I need to dynamically reference. It's a generic function to handle multiple buttons. Help private void SQLButton(object sender, EventArgs e) { magic(((Button)sender).Tag.ToString()); } private void magic(string currentcombo) { string CurrentText = (Comb...

dynamic casting?

I need a way to cast an object to a type that is not know at compiler time. something like this: object obj; public (type of obj) Obj { get { return obj } set { obj = (type of obj)value; } } The only thing that is know is that obj is a value type. I doubt that something like this would be pos...

MySQL: Typecasting NULL to 0

Hi all, Let us suppose the following table (e.g. a result of several inner join statements): id | column_1 | column_2 ------------------------ 1 | 1 | 2 | 2 | 2 3 | | 3 Which you could for example get from the following statement: select a.id, t1.column_1, t2.column_2 from a left join t1 on a.id = t1.id le...

In this scenario, how to frame a common function and parameterize casting?

These are the 2 sets of activities : //#1 List<object> AFilterObject = A_List.SelectedList; List<A> AFilters = new List<A>(); foreach (Aitem in AFilterObject ) { //Do activity X } //#2 List<object> BFilterObj = B_List.SelectedList; List<B> payopFilters =...

Flex and Zend_AMF: How do I get a Flex arrayCollection from Flex into PHP?

I currently have an arrayCollection in Flex and I want to sent it to PHP (Zend_AMF). According to the Zend_AMF wiki, sending an arrayCollection over directly will force Zend_AMF to cast the arrayCollection as an object which is no good. I'd rather have an array of my models. I assume the best way would be to convert the arrayCollection...

How to dynamically cast an object of type string to an object of type T

I have this XML document <AdditionalParameters> <PublishToPdf Type ="System.Boolean">False</PublishToPdf> </AdditionalParameters> in my code and I'm trying to build an array of arguments containing the <PublishToPdf> node. object test = (object) ((typeof(publishNode.Attributes["Type"].value)) publishNode.InnerText); This breaks at ...

Getting rid of error C2243

Is it possible to getting rid of error C2243? class B {}; class D : protected B {}; D d; B *p = &d; // conversion from 'D *' to 'B &' exists, but is inaccessible I had this error in my app and at the end I've managed to compile it by making an explicit conversion: D d; B *p = (B*)&d; I can't understand why by making class D inhe...

C++ Templates type casting with derivates

Hi, I'm trying to cast from one generic to another, say: myClass<MoreAbstract> anItem = myclass<DerivateFromMoreAbstract> anotherObject; Or do something like aFunction(anotherObject); // myclass<DerivateFromMoreAbstract> anotherObject where aFunction signature is aFunction(myClass<MoreAbstract> item); In fact, myClass is actual...

ASP.Net Error - Unable to cast object of type 'System.String' to type 'System.Data.DataTable'.

I get the below error Unable to cast object of type 'System.String' to type 'System.Data.DataTable'. This is the code I'm using Dim str As String = String.Empty If (Session("Brief") IsNot Nothing) Then Dim dt As DataTable = Session("Brief") If (dt.Rows.Count > 0) Then For Each dr As DataRow In dt.Rows...

String variable to a DefaultMutableTreeNode object?

Is it possible to convert a String variable to a DefaultMutableTreeNode object? Please explain. Context: String s = new String(outputTagName); Object s2 = (Object) s; DefaultMutableTreeNode selectedNode2 =(DefaultMutableTreeNode) s2; DefaultMutableTreeNode parent2 =(DefaultMutableTreeNode) parent; model.insertNodeInto(selectedNode2, ...

Ansi SQL type casting

Is it allowed to cast types in ANSI SQL like in postgres for example: SELECT SUM( CAST(qnty AS int) - CAST(reserve AS int) ) AS sum ... qnty and reserve are character columns. ...

Why do i need to wrap this code in a cast to short?

If i have some code like the following: short myShortA = 54; short myShortB = 12; short myShortC = (short)(myShortA - myShortB); Both operands are shorts and it's going into a short so why do i have to cast it? ...

Cast a variable to a type represented by another Type variable?

I'm aware that questions like this have been asked before and I doubt it's possible, but I just wanted to make 100% sure that it isn't. In VB.net or C# (either language, it doesn't matter), I want to cast a variable to a type represented by another Type variable. Here's an example of the kind of code that would be needed in C#: Object...

Warning when type-casting between pointer and pointer-to-function

I am porting some C code to a TI DSP chip environment. I'm grappling with the C compiler. I have a data structure that includes a pointer to a function. I have a function that initializes the data structure. Something like this: typedef void (*PFN_FOO)(int x, int y); struct my_struct { PFN_FOO pfn; }; init_struct(struct my_str...