elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Los 10 CVE más críticos (peligrosos) de 2020


  Mostrar Mensajes
Páginas: 1 ... 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 [50] 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 ... 331
491  Programación / Programación C/C++ / Re: Multi-Threading con winpcap. en: 13 Marzo 2012, 03:11 am
Ahora no crashea, pero se cierra el programa...
Como puedo hacer para mantenerlo funcionando??

no habia leido bien esto...

usa

pthread_join();

Para detener el hilo madre que creo los hijos, para que asi sigan los hijos como si nada hasta que todos terminen,

Dulces Lunas!¡.
492  Programación / Programación C/C++ / Re: Multi-Threading con winpcap. en: 12 Marzo 2012, 21:00 pm
Seguro que pthread_create() no tira un segfault.? Recuerdo que tenia que llamar a ptw32_processInitialize() antes de crear un nuevo hilo sobre MinGW...

De hecho si tiene su segfault y es por que hace uso de delete en la siguiente linea despues de crear el hilo y el hilo intenta acceder a la memoria ya eliminada... tambien por lo del & en el casting el parametro del proceso hijo.

Dulces Lunas!¡.
493  Programación / Programación C/C++ / Re: Multi-Threading con winpcap. en: 12 Marzo 2012, 20:49 pm
Código
  1.        char *pszIname = new char[strlen(d->name)];
  2.        ZeroMemory(pszIname, strlen(d->name));
  3.        strcpy(pszIname, d->name);
  4.       delete pszIname;
  5.  

Debes sumarle un 1 a strlen(d->name) este byte mas es el byte nulo de termino de cadena...
No liberes la memoria despues de la creacion del hilo (delete), en lugar de esto usa pthread_exit(di) para que pthread_join() te retorne el puntero a esta memoria y puedas liberarla con delete tambien puedes usar pthread_detach() para que no gastes la pila de retornos d elos hilos si ocupas pthread_exit(NULL)

Código
  1.  
  2. void *HandleAdapter(void *di)
  3. {
  4.    do rand();
  5.    while(true);
  6.    char *d =  (char*) di;
  7.    cout << d << endl;
  8. ...
  9.  
  10.  

las lineas sombreadas quitalas no sirven de nada... el casting ponlo sin el signo & tal cual de lo dejo arriba.

Leete la documentacion de pthread, leete un manual de C/C++ basico... ya que por lo que veo te confundes un poco aun.

http://pubs.opengroup.org/onlinepubs/009604599/functions/pthread_detach.html

Dulces Lunas!¡.
494  Programación / .NET (C#, VB.NET, ASP) / Re: Problema permisos con System.Diagnostics.Process en: 12 Marzo 2012, 20:38 pm
http://msdn.microsoft.com/en-us/library/windows/desktop/ms683179(v=vs.85).aspx

Dulces Lunas!¡.
495  Programación / Programación Visual Basic / Re: apagado de pc en vb en: 7 Marzo 2012, 05:38 am
http://msdn.microsoft.com/en-us/library/windows/desktop/aa379295(v=vs.85).aspx

Citar
Return value

 If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

Close the access token handle returned through the TokenHandle parameter by calling CloseHandle.


Dulces Lunas!¡.
496  Programación / Programación C/C++ / Re: Como hacer un programa que guarde en un fichero todo lo que se pone por teclado? en: 6 Marzo 2012, 19:53 pm
fwrite()

Dulces Lunas!¡.
497  Foros Generales / Foro Libre / Re: Siempre abrá inseguridad en la Informática ? en: 5 Marzo 2012, 20:04 pm
errar es de humanos, nunca habra sistema inquebrantable...

bien dicho.

Dulces Lunas!¡.
498  Programación / Programación Visual Basic / Re: cast parametro null en: 5 Marzo 2012, 20:01 pm
.
Si declaras la API como en la MSDN tendrías que usar así los parámetros, ¿como tienes declarada la API?. Todo depende de la declaración API...

Código
  1.  
  2.    if ( not AdjustTokenPrivileges(hToken, FALSE, byval varptr(tkp), LenB(TOKEN_PRIVILEGES), &H0&,  &H0& ) ) then
  3.    ...
  4.    end if
  5.  
  6.  

Sangrientas Lunas!¡.
499  Programación / Programación Visual Basic / Re: ¿Números aleatorios sin repetición? en: 3 Marzo 2012, 07:32 am
.
NO USES Randomize con ciclos do while o ciclos muy cortos NO FUNCIONA, es mejor no usar Randomize a mi criterio.

Te dejo mi código (viene con un ejemplo de la utilización de la clase):

CRandNumberNR.cls

Dulces Lunas!¡.
500  Programación / Programación C/C++ / Re: Insertar imágenes en C con Open GL en: 28 Febrero 2012, 19:22 pm
La pagina de Nehe tiene buenas guías mírate estos:

http://nehe.gamedev.net/tutorial/lessons_06__10/17010/



1ro debes cargar la imagen:

    glGenTextures(1 , &this->uiID);   // Generamos la ID de la textura
    glBindTexture(GL_TEXTURE_2D , this->uiID-1);
    glTexParameteri(GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_LINEAR);

// Una vez creado el ID para la tectura debes cargarla y asignarla a este ID...

::glBindTexture( GL_TEXTURE_2D, this->uiID);
        ::glTexImage2D(GL_TEXTURE_2D,
                       0,
                       3,
                       oBMPReader.getInfo().bmiHeader.biWidth,
                       oBMPReader.getInfo().bmiHeader.biHeight,
                       0,
                       GL_RGB,
                       GL_UNSIGNED_BYTE,
                       (GLvoid*)oBMPReader.getBytes().lpData);

Para implementarla debes usar

    if(this->uiID > 0 && this->enabled)
        ::glBindTexture(GL_TEXTURE_2D , this->uiID - 1);
    else
        ::glBindTexture(GL_TEXTURE_2D , 0);

Para poderla dibujar debes definir antes los vértices que definen la textura a implementar y (estos vertices pueden inclusive estirar la textura) de la textura:

glTexCoord3f();

Antes de llamar a

glVertex3f();

Te dejo mis clases con las que realizo estas acciones:

CTexture.h
Código:
#ifndef CTexture_H
#define CTexture_H

#include "native.h"
#include "_Formatos/mBitmap/CBMPReader.h"
#include <windows.h>
#include <GL/glut.h>

class CGL_Texture;
typedef CGL_Texture CGL_TEXTURE, *LPCGL_TEXTURE;

class CGL_Texture: public Object
{
private:
    unsigned int uiID;
    void create();
    bool bLoadBMP;

public:
    CGL_Texture();
    ~CGL_Texture();

    bool itsLoad();
    bool enabled;
    void remove();
    void use();
    bool loadBMP(const char* szFile);
};

#endif // CTexture_H


CTexture.cpp
Código:

#include "OpenGL/ctexture.h"

//---------------------------------------------------------------
// Nombre: Constructor
// Descripcion: Constructor de la clase. Inicializa las variables
// Parametros: Ninguno
//---------------------------------------------------------------
CGL_Texture::CGL_Texture():
Object()
{
    this->uiID = 0;
    this->enabled = false;
    this->bLoadBMP = false;
}

//---------------------------------------------------------------
// Nombre: Destructor
// Descripcion: Destructor de la clase. Elimina la textura
// Parametros: Ninguno
//---------------------------------------------------------------
CGL_Texture::~CGL_Texture()
{
    this->remove();
}

//---------------------------------------------------------------
// Nombre: Crear
// Descripcion: Establece los parámetros GL para cargar
// Parametros:
//                char* szNombreFichero: Nombre del fichero a cargar
//---------------------------------------------------------------
void CGL_Texture::create()
{
    this->remove();
    ::glGenTextures(1 , &this->uiID);   // Generamos la ID de la textura
    this->uiID++;    // Usamos un offset de +1 para diferenciar del estado no-inicializado
    ::glBindTexture(GL_TEXTURE_2D , this->uiID-1);
    ::glTexParameteri(GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_LINEAR);
    ::glTexParameteri(GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_LINEAR);
}
//---------------------------------------------------------------
// Nombre: Elimina
// Descripcion: Elimina la textura
// Parametros: Ninguno
//---------------------------------------------------------------
void CGL_Texture::remove()
{
    if( this->uiID > 0)
        ::glDeleteTextures(1 , &(--this->uiID));
    this->uiID = 0;
    this->bLoadBMP = false;
}

//---------------------------------------------------------------
// Nombre: Usa
// Descripcion: Usa la textura actual
// Parametros: Ninguno
//---------------------------------------------------------------
void CGL_Texture::use()
{
    if(this->uiID > 0 && this->enabled)
        ::glBindTexture(GL_TEXTURE_2D , this->uiID - 1);
    else
        ::glBindTexture(GL_TEXTURE_2D , 0);
}

//---------------------------------------------------------------
// Nombre: CargarBMP
// Descripcion: Carga un fichero BMP y almacena los datos
// Parametros: Ninguno
//---------------------------------------------------------------
bool CGL_Texture::loadBMP(const char *szFile)
{
    CBMPReader oBMPReader;
    this->remove();
    if(oBMPReader.loadBMP(szFile) != NULL)
    {
        this->create();
        ::glBindTexture( GL_TEXTURE_2D, this->uiID);
        ::glTexImage2D(GL_TEXTURE_2D,
                       0,
                       3,
                       oBMPReader.getInfo().bmiHeader.biWidth,
                       oBMPReader.getInfo().bmiHeader.biHeight,
                       0,
                       GL_RGB,
                       GL_UNSIGNED_BYTE,
                       (GLvoid*)oBMPReader.getBytes().lpData);
        return this->bLoadBMP = true;
    }
    return this->bLoadBMP = false;
}

//---------------------------------------------------------------
// Nombre: itsLoad
// Descripcion: Esta cargada la textura en memoria?.
// Parametros: Ninguno
//---------------------------------------------------------------
bool
CGL_Texture::itsLoad()
{
    return this->bLoadBMP;
}


CDrawn.h
Código:

#ifndef CGL_DRAWN_H
#define CGL_DRAWN_H

#include <windows.h>
#include <stack>
#include "native.h"
#include "OpenGL/cglobject.h"

using namespace std;

class CGL_Drawn;
typedef CGL_Drawn CGL_DRAWN, *LPCGL_DRAWN;

class CGL_Drawn: public Object, public stack<LPCGL_OBJECT>
{
public:
    CGL_Drawn();
    CGL_Drawn(int idWin);
    virtual ~CGL_Drawn();
    int draw();
    int draw(int idWin);
protected:
    int idWin;
private:
};

#endif // CGL_DRAWN_H


CDrawn.cpp
Código:

#include "OpenGL/cdrawn.h"

#include <iostream>
#include <algorithm>

using namespace std;

CGL_Drawn::CGL_Drawn(int idWin):
    Object()
{
    this->idWin = idWin;
    //ctor
}

CGL_Drawn::CGL_Drawn():
    Object(), idWin(0)
{
    //ctor
}

CGL_Drawn::~CGL_Drawn()
{
    //dtor
}

int CGL_Drawn::draw()
{
    return this->draw(idWin);
}

int CGL_Drawn::draw(int idWin)
{
    LPCGL_OBJECT lpCGL_Object = NULL;
    LPCASE_MATERIAL lpMaterial = NULL;
    LPCASE_MESH lpCASE_Mesh = NULL;
    TAnimObject* lpAniObj = NULL;
    int iRet = 0,
        n = 0,
        tv = 0,
        v = 0;
    int i = 0,
    j = 0;

    float fMax = 0.0f;

    ::glutPushWindow();
    ::glutSetWindow(idWin);

    while(!this->empty())
    {
        ::glPushMatrix();

        lpCGL_Object = this->top();
        lpCASE_Mesh = lpCGL_Object->lpCASE_Object->lpMesh;

        ::glTranslatef(lpCGL_Object->x, lpCGL_Object->y, lpCGL_Object->z);

        /// Animación...
        lpAniObj = &lpCGL_Object->lpCASE_Object->udtAnimate.udtAnimObject;

        if (lpAniObj->iPosCount)
        {
            if (lpAniObj->iStepPos >= lpAniObj->iPosCount)
                lpAniObj->iStepPos = 0;
            ::glTranslatef(lpAniObj->lpPosTrack[i]->fPosition[0],
                           lpAniObj->lpPosTrack[i]->fPosition[1],
                           lpAniObj->lpPosTrack[i]->fPosition[2]);
            lpAniObj->iStepPos++;
        }
        else
        {
            ::glTranslatef(lpCGL_Object->lpCASE_Object->lpNodeTM->fTMPos[0],
                           lpCGL_Object->lpCASE_Object->lpNodeTM->fTMPos[1],
                           lpCGL_Object->lpCASE_Object->lpNodeTM->fTMPos[2]);
        }

        if (lpAniObj->iRotCount)
        {
            if (lpAniObj->iStepRot >= lpAniObj->iRotCount)
                lpAniObj->iStepRot = 0;
            ::glRotatef(lpAniObj->lpRotTrack[lpAniObj->iStepRot]->fAngle,
                        lpAniObj->lpRotTrack[lpAniObj->iStepRot]->fAxis[0],
                        lpAniObj->lpRotTrack[lpAniObj->iStepRot]->fAxis[1],
                        lpAniObj->lpRotTrack[lpAniObj->iStepRot]->fAxis[2]);
            lpAniObj->iStepPos++;
        }
        else
        {
            ::glRotatef(lpCGL_Object->lpCASE_Object->lpNodeTM->fTMRotAngle,
                        lpCGL_Object->lpCASE_Object->lpNodeTM->fTMRotAxis[0],
                        lpCGL_Object->lpCASE_Object->lpNodeTM->fTMRotAxis[1],
                        lpCGL_Object->lpCASE_Object->lpNodeTM->fTMRotAxis[2]);
        }

        /// End

        //cout << lpCGL_Object->lpCASE_Object->sNodeName << "\t" << lpCGL_Object->lpCASE_Object->iMaterialRef <<endl;

        if (lpCGL_Object->lpCASE_Object->iMaterialRef != -1)
            lpMaterial = lpCGL_Object->lpCASE_Object->lpModels->listMaterials[lpCGL_Object->lpCASE_Object->iMaterialRef];


        if (lpMaterial)
        {
            ::glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, lpMaterial->fMaterialAmbient);
            ::glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, lpMaterial->fMaterialDiffuse);
            ::glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, lpMaterial->fMaterialSpecular);
            ::glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, lpMaterial->fMaterialShine);
        }

        if (lpMaterial)
            ::glColor3fv(lpMaterial->fMaterialDiffuse);

        //  Aplicar color o Textura al objeto.
        ::glColor3fv(lpCGL_Object->lpCASE_Object->fWireFameColor);

        //  Malla de Poligonos.
        for(v = 0 ; v < lpCASE_Mesh->listFace.size(); ++v)
        {
            ::glBegin(GL_TRIANGLES);
            for(n = 0 ; n < 3 ; ++n)                 //  Vertices(Triangulos).
            {
                if(lpCGL_Object->oTexture.itsLoad())// && lpCGL_Object->oTexture.enabled)         //  Textura.
                {
                    switch(n)
                    {
                    case 0: tv = lpCASE_Mesh->listTFace[v]->ia; break;
                    case 1: tv = lpCASE_Mesh->listTFace[v]->ib; break;
                    case 2: tv = lpCASE_Mesh->listTFace[v]->ic; break;
                    }
                    lpCGL_Object->oTexture.use();
                    ::glTexCoord3f(lpCASE_Mesh->listTVertex[tv]->fx,
                                   lpCASE_Mesh->listTVertex[tv]->fy,
                                   lpCASE_Mesh->listTVertex[tv]->fz);
                }   //  Textura
                //cout << lpCASE_Mesh->listFace.size() << "\t" << n << "\t" << v << "\t" << endl;
                switch(n)
                {
                case 0: tv = lpCASE_Mesh->listFace[v]->ia; break;
                case 1: tv = lpCASE_Mesh->listFace[v]->ib; break;
                case 2: tv = lpCASE_Mesh->listFace[v]->ic; break;
                }
                ::glVertex3f(lpCASE_Mesh->listVertex[tv]->fx,
                             lpCASE_Mesh->listVertex[tv]->fy,
                             lpCASE_Mesh->listVertex[tv]->fz);
            }
        }   //  v < lpCASE_Mesh->ListFace.size();

        ::glEnd();
        iRet++;
        this->pop();

        ::glPopMatrix();
    }

//    cout << fMax << endl;

    ::glutPopWindow();

    return iRet;
}


P.D.: No son todos los archivos de mi proyecto... solo te los dejo para/como Guía.

Dulces Lunas!¡.
Páginas: 1 ... 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 [50] 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 ... 331
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines