首页 \ 问答 \ DialogProc函数要求声明它自身静态[重复](DialogProc function asking to declare it self static [duplicate])

DialogProc函数要求声明它自身静态[重复](DialogProc function asking to declare it self static [duplicate])

这个问题在这里已有答案:

这是我的createialogparam函数,它从这里调用DialogProc函数 -

 HRESULT AMEPreviewHandler::CreatePreviewWindow()
    {
        assert(m_hwndPreview == NULL);
        assert(m_hwndParent != NULL);
        HRESULT hr = S_OK;

        m_hwndPreview = CreateDialogParam( g_hInst,MAKEINTRESOURCE(IDD_MAINDIALOG), m_hwndParent,(DLGPROC)DialogProc, (LPARAM)this); /here the dialog proc function is called
        if (m_hwndPreview == NULL)
        {
          hr = HRESULT_FROM_WIN32(GetLastError());
        }
    ..........
    ...
    }

这是DialogProc函数的定义 -

BOOL CALLBACK AMEPreviewHandler::DialogProc(HWND m_hwndPreview, UINT Umsg, WPARAM wParam, LPARAM lParam) 
    { 
        static RECT m_rcParent ;

        switch(Umsg)
        {
        case WM_INITDIALOG: 
            {
            return 0;
            }
            break;
........
case WM_COMMAND:
            {  
                int ctl = LOWORD(wParam);
                int event = HIWORD(wParam);

                if (ctl == IDC_PREVIOUS && event == BN_CLICKED ) 
                {         

                    CreateHtmlPreview(); //it must be static now and it is not able to access the non static vraibles delared globally in the program
                    return 0;
                }     
}
}

而声明是这样的 -

static BOOL CALLBACK DialogProc(HWND hWindow,UINT uMsg,WPARAM wParam,LPARAM lParam); //假设它是静态的..如果静态则没有给出任何错误。如果它没有被声明为静态,则会给出错误
这里 -

m_hwndPreview = CreateDialogParam( g_hInst,MAKEINTRESOURCE(IDD_MAINDIALOG), m_hwndParent,(DLGPROC)DialogProc, (LPARAM)this); //error C2440: 'type cast' : cannot convert from 'overloaded-function' to 'DLGPROC'

有没有办法在静态DialogProc中访问全局声明的变量,或者可以访问dialogproc中的全局声明的变量而不将这些变量声明为静态,因为它们在程序的其他部分也被用作非静态变量?


This question already has an answer here:

here is my createdialogparam function which is calling DialogProc function from here-

 HRESULT AMEPreviewHandler::CreatePreviewWindow()
    {
        assert(m_hwndPreview == NULL);
        assert(m_hwndParent != NULL);
        HRESULT hr = S_OK;

        m_hwndPreview = CreateDialogParam( g_hInst,MAKEINTRESOURCE(IDD_MAINDIALOG), m_hwndParent,(DLGPROC)DialogProc, (LPARAM)this); /here the dialog proc function is called
        if (m_hwndPreview == NULL)
        {
          hr = HRESULT_FROM_WIN32(GetLastError());
        }
    ..........
    ...
    }

here is the definition of DialogProc function-

BOOL CALLBACK AMEPreviewHandler::DialogProc(HWND m_hwndPreview, UINT Umsg, WPARAM wParam, LPARAM lParam) 
    { 
        static RECT m_rcParent ;

        switch(Umsg)
        {
        case WM_INITDIALOG: 
            {
            return 0;
            }
            break;
........
case WM_COMMAND:
            {  
                int ctl = LOWORD(wParam);
                int event = HIWORD(wParam);

                if (ctl == IDC_PREVIOUS && event == BN_CLICKED ) 
                {         

                    CreateHtmlPreview(); //it must be static now and it is not able to access the non static vraibles delared globally in the program
                    return 0;
                }     
}
}

and the declaration is like this-

static BOOL CALLBACK DialogProc(HWND hWindow, UINT uMsg, WPARAM wParam, LPARAM lParam); //suppose it is static ..it is not giving any error if static ..If it is not declared static it gives error
here -

m_hwndPreview = CreateDialogParam( g_hInst,MAKEINTRESOURCE(IDD_MAINDIALOG), m_hwndParent,(DLGPROC)DialogProc, (LPARAM)this); //error C2440: 'type cast' : cannot convert from 'overloaded-function' to 'DLGPROC'

Is there any way to access the globally declared variables inside the static DialogProc or it is possible to access the globally declared variables inside the dialogproc without declaring the those variables as static because t hey are also used as non static in other part of program ??


原文:https://stackoverflow.com/questions/17790479
更新时间:2023-10-17 11:10

最满意答案

  1. 冗余呼叫ensureIndex是空操作。
  2. 如果ensureIndex调用中引用的集合不存在,它将被创建。
  3. 一次就够了。
  4. 除非您指定background: true选项,否则创建索引会阻止其他数据库操作。

MongoDB 3.0更新

ensureIndex在v3.0中已弃用,现在是createIndex的别名,因此应该使用createIndex 。 行为保持不变。


  1. Redundant calls to ensureIndex are no-ops.
  2. If the collection referenced in the ensureIndex call doesn't exist it will be created.
  3. Once is enough.
  4. Unless you specify the background: true option, creating an index blocks other database operations.

MongoDB 3.0 Update

ensureIndex was deprecated in v3.0 and is now an alias for createIndex, so createIndex should be used instead. The behavior remains the same.

相关问答

更多
  • 更新2:原始答案以及第一次更新错误地引用了Mongo shell文档,而不是Java API。 在Java中, DBCollection.ensureIndex()在版本2.12中被弃用,并在版本3.0中被删除。 DBCollection.createIndex()是应该使用的。 更新: 从3.0.0版开始,不推荐使用db.collection.ensureIndex() 。 现在是db.collection.createIndex()的别名。 原版的: 自1.8开始, createIndex()已弃用 它 ...
  • 看来我的评论有点被误解了,所以我会澄清一下。 只要你在第一次调用find()之前调用它, 那么调用它并不重要。 换句话说,创建索引时无关紧要,只要它在您期望使用它之前就已经存在了。 我见过很多的常见模式是在find()调用的同时(和在同一个地方)对ensureIndex进行编码。 ensureIndex将检查索引是否存在,如果不存在则创建它。 在调用find()之前调用ensureindex毫无疑问存在一些开销(虽然非常小),所以最好不要这样做。 我在代码中调用ensureIndex来简化部署并避免单独管理 ...
  • 请记住,在Mongo 3.x中, sureIndex已被弃用,应该不鼓励。 自3.0.0版本以来已弃用:db.collection.ensureIndex()现在是db.collection.createIndex()的别名。 同样在pymongo : DEPRECATED - 确保此集合上存在索引。 这意味着您应该始终使用create_index 。 Keep in mind that in Mongo 3.x ensureIndex is deprecated and should be discour ...
  • 冗余呼叫ensureIndex是空操作。 如果ensureIndex调用中引用的集合不存在,它将被创建。 一次就够了。 除非您指定background: true选项,否则创建索引会阻止其他数据库操作。 MongoDB 3.0更新 ensureIndex在v3.0中已弃用,现在是createIndex的别名,因此应该使用createIndex 。 行为保持不变。 Redundant calls to ensureIndex are no-ops. If the collection referenced i ...
  • 是的,MongoDB中的_id始终是唯一的。 它是主键,这就是为什么不需要设置UNIQUE原因。 Yes, _id in MongoDB is always unique. It's the primary key, which is why setting UNIQUE isn't necessary.
  • 我应该创建这样的复合索引: db.items.ensureIndex({age:1,brand:1,零售商:1,性别:1,样式:1,位置:1,颜色:1,关键字:1}) 您可以创建一个类似上面的索引,但您几乎将整个集合编入索引。 索引占用空间; 索引中的字段越多,使用的空间就越多。 通常是RAM,虽然它们可以换掉。 他们还会受到处罚。 您的索引似乎很浪费,因为可能只索引其中一些字段会使MongoDB扫描一组接近查找操作预期结果的文档。 我可以创建一组更好的索引来优化此查询吗? 就像我之前说过的那样,可能是的。 ...
  • 在当前的Mongoose 4.3.7版本中,您不能在方案中定义部分索引,但仍然可以使用MongoDB 3.2的部分索引。 您只需使用本机驱动程序创建索引。 // ScheduleModel is a Mongoose Model ScheduleModel.collection.createIndex({"type" : 1 } , {background:true , partialFilterExpression : { type :"g" }} , function(err , result){ ...
  • 目前,索引(无论是否唯一)对整个集合起作用,而不是每个子文档。 如果你想在子文档上有某种独特性,你可以使用查询魔术: db.c.update({ name: 'Sammaye', 'permission.group': {$ne: ObjectId()} }, {$push:{permission:{group: ObjectId(), u: 31}}}); 这当然只会在sammaye尚未具有该特定group条目时更新。 随意根据需要进行修改。 Currently indexes, uni ...
  • MongoDB每个查询一次只能使用一个索引,因此您创建两个索引的建议将无效。 相反,我会创建一个复合索引: > db.foo.ensureIndex({"tag_cloud.value": 1, "tag_cloud.count": -1}) 此索引既可以用于过滤到您要考虑的特定元素,也可以按降序排序返回: > db.foo.find({"tag_cloud.value":"games"}).sort({"tag_cloud.count":-1}).explain() { "cursor" : " ...
  • 使用MongoDB的应用程序重新启动。 随后对ensureIndex()的调用是否会导致完整的重新索引? 不,它应该(如在其他所有驱动程序中)注册为无操作,因为索引已经存在。 一些驱动程序提供了一种缓存机制,可以在不进入服务器的情况下检测是否已创建索引(即Python)。 MongoDB服务器重新启动。 稍后从客户端应用程序调用ensureIndex()会重建吗? 与上面相同 是否有多个客户端会话影响了这些? 我假设根据文档,索引在整个集合中是全局的:“MongoDB在每个集合级别定义索引。” 是的索引存储 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)