error C2440: 'type cast' HELP!!

This is a discussion on error C2440: 'type cast' HELP!! within the C++ Programming forums, part of the General Programming Boards category; Hi All, I am having problems with the following bit of code. Code: void setTxParams(int h, int s, int p) ...

  1. #1
    Registered User
    Join Date
    Feb 2006
    Location
    Ballincollig, co. cork, Eire
    Posts
    22

    error C2440: 'type cast' HELP!!

    Hi All,

    I am having problems with the following bit of code.

    Code:
    void setTxParams(int h, int s, int p)
    {
    	ETHTransmit Tx;
    	//Transmit Parameters
    	Tx.ucTransmitMode = SINGLE_BURST_MODE;
    	Tx.ulBurstCount = 10000;
    	Tx.ucDuplexMode = HALFDUPLEX_MODE;
    	Tx.ucSpeed = SPEED_100MHZ;
    	Tx.ulInterFrameGap = 960;
    	Tx.uiInterFrameGapScale = NANO_SCALE;
    	//VFD1 Parameters
    	Tx.ucVFD1Mode = HVFD_INCR;
    	Tx.iVFD1Range = 6;
    	Tx.uiVFD1Offset = 48;
    	unsigned char vfdPattern[6];
    	vfdPattern[1] = 0x11;
    	vfdPattern[2] = 0x22;
    	vfdPattern[3] = 0x33;
    	vfdPattern[4] = 0x44;
    	vfdPattern[5] = 0x55;
    	vfdPattern[6] = 0x66;
    	memcpy(Tx.ucVFD1Pattern, vfdPattern, 6);
    	//Tx.ucVFD1Pattern = vfdPattern;
    	Tx.uiVFD1CycleCount = 5;
    	//VFD3 Parameters
    	Tx.ucVFD3Mode = HVFD_ENABLED;
    	Tx.uiVFD3Range = 2;
    	Tx.uiVFD3Offset = 96;
    	unsigned char vfdBuffer[6];
    	vfdBuffer[1] = 0x08;
    	vfdBuffer[2] = 0x00;
    	vfdBuffer[3] = 0x08;
    	vfdBuffer[4] = 0x06;
    	vfdBuffer[5] = 0x81;
    	vfdBuffer[6] = 0x37;
    	memcpy(Tx.ucVFD3Buffer, vfdBuffer, 6);
    	//Tx.ucVFD3Buffer = vfdBuffer;
    	Tx.uiVFD3DataCount = 6;
    
    
    	CHECKERROR(HTSetStructure(ETH_TRANSMIT, 0, 0, 0, 
    		(void*) Tx, sizeof(Tx), h, s, p));
    }
    The error I keep getting is the following:

    error C2440: 'type cast' : cannot convert from 'ETHTransmit' to 'void *
    '

    which is associated with the following line

    Code:
    CHECKERROR(HTSetStructure(ETH_TRANSMIT, 0, 0, 0, 
    		(void*) Tx, sizeof(Tx), h, s, p));
    According to the documentation I am consulting when doing this, the function HTSetStructure must be in the following form.

    Code:
    int HTSetStructure(int iType1, int iType2, int iType3, int iType4,
    void* pData, int iLen, int iHub, int iSlot, int iPort);
    Does anybody have any ideas what I am doing wrong and how to fix it?

    Regards

    Brownie

    //Microsoft Visual C++ Express 2008 on Windows XP

  2. #2
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    &Tx gives you the address of Tx. Tx itself is not a pointer and thus cant be cast to a void pointer
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  3. #3
    Registered User
    Join Date
    Feb 2006
    Location
    Ballincollig, co. cork, Eire
    Posts
    22
    Thanks.... Pointers have always confused me.

    Brownie

  4. #4
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    no prob
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,452
    Think of it like this.
    A pointer contains an address. Each object and variable has an address, because it must "live" somewhere, yes?
    So say that variable represents a paper. You can't hand the actual paper to someone who expects the address where that paper is located, can you (or rather, should you)?
    No. You should give the address instead (and that's the job of the & operator).

    You may also read my pointers analogy:
    Memory Functions - Still Learning
    (Remember to use new/delete instead of malloc/calloc/free.)
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting the matrix question..
    By transgalactic2 in forum C Programming
    Replies: 47
    Last Post: 12-22-2008, 02:17 PM
  2. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 03:49 AM
  5. Erros in Utility Header File
    By silk.odyssey in forum C++ Programming
    Replies: 4
    Last Post: 12-22-2003, 05:17 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21